Validating a serializer whose source is model data

40 views
Skip to first unread message

David Jackson

unread,
Dec 21, 2020, 5:00:47 PM12/21/20
to Django REST framework
I have a ModelSerializer that I wish to require certain fields, even though it is possible for the model it is based on to have null values for those fields.

However, I cannot instantiate a serializer like this:
`s = MySerializer(model_instance)`

and then call `s.is_valid()` since that method only works if I initialized the serializer with a dictionary.

If I just create the serializer and grab the data from it without attempting to call is_valid, it does not respect the constraints in the serializer itself.

Any suggestions on how to solve this problem?

Thanks!

Lakshman Kumar

unread,
Dec 22, 2020, 10:51:01 AM12/22/20
to Django REST framework
sorry i didn't understand. could you please let me know what you want.
Reply all
Reply to author
Forward
0 new messages