Partial updates with DjangoModelFormMutation
Django's ModelForm sets all specified fields to None when you don't pass in the data. It's possible that this doesn't happen when using a DRF serializer instead (I haven't tried it). Overriding the ModelForm's __init__ method like this seems to work:
class BaseModelForm(ModelForm):
def __init__(self, *args, **kwargs):
super(BaseModelForm, self).__init__(*args, **kwargs)
# if form has being submitted and
# model instance exists, then get data
if self.is_bound and self.instance.pk:
# get current model values
modeldict = model_to_dict(self.instance)
modeldict.update(self.data)
# add instance values to data
self.data = modeldict
But this should really be default behavior for DjangoModelFormMutation.
Should I use this BaseModelForm insted of ModelForm?
@soumita018
Yes unless you want your data to be overwritten. I would recommend you use serializers instead though.
This is a really critical bug, unless I'm not totally mistaken.
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Considering the project is dead now, I'm removing myself as assignee. I wouldn't recommend expecting a fix.