python - django modelformset_factory POST request data retrieval -
i got django 1.9 , found out modelformset_factory useful can setup forms without major afford.
now came realise upon submitting form (post method)i need figure out objects have added , removed .
this view got :
def def_accounts(request): list_services_list() services_list_topicformset = modelformset_factory(services_list, form=services_list_nameform, fields=('accounts',), can_delete=true) items = services_list.objects.all() formset = services_list_topicformset(queryset = items) if request.method == 'post': t_formset = services_list_topicformset(request.post) if t_formset.is_valid(): t_formset.save()
i have looked post request , seems full data submission, seems doing full object refresh cannot distinguish post action in there..
any on this?
thanks!
edit seems can figure object being added toe form follows:
if t_formset.is_valid(): instances = t_formset.save() instance in instances: print "instance.id: " + str(instance.id) print "instance.accounts: " + str(instance.accounts) instance.save()
output:
> instance.id: 21 > instance.accounts: test1
still trying figure out how can objects being deleted!
any idea?
thanks!
when save model formset calling formset.save()
, 3 attributes formset.changed_objects
, formset_deleted_objects
, formset.new_objects
store changed, deleted , new objects respectively.
therefore, can access deleted objects formset.deleted_objects
.
Comments
Post a Comment