With django-rest-framework how do I assign a field to the request user when using a ModelViewSet? -
With django-rest-framework how do I assign a field to the request user when using a ModelViewSet? -
the documentation recommends apiviews:
def pre_save(self, obj): obj.owner = self.request.user this doesn't seem work back:
class="lang-js prettyprint-override">{ "owner": [ "this field cannot null." ] } edit: pre_save method never gets called. checked inserting phone call pdb in pre_save method.
my serializer plain hyperlinkedmodelserializer model , list of fields specified in meta.
on model had overridden clean_fields. signature clean_fields:
model.clean_fields(exclude=none) my custom clean_fields:
def clean_fields(self, exclude=none): super(applicant, self).clean_fields() # bug here. # custom clean_fields code i didn't pass exclude parameter super class!
oh god took me many hours debug.
django django-rest-framework
Comments
Post a Comment