The "blank=True" attribute in Django only applies to form validation and has no effect on API requests. When executing a PUT request, Django REST Framework will check for the presence of the field in the request data. If it is not present, it will raise a "This field may not be blank" error even if "blank=True" is set on the model field.
To allow the field to be optional in API requests, you can add "required=False" to the serializer field for that model field. This will tell Django REST Framework to not raise an error if the field is missing in the request data. For example:
class MyEmbeddedModelSerializer(serializers.ModelSerializer):
my_field = EmbeddedModelField(MyEmbeddedModel, required=False)
class Meta:
model = MyModel
fields = ('id', 'my_field', ...)
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-06-25 20:09:35 +0000
Seen: 13 times
Last updated: Jun 25 '23
Despite setting `verbose` to `False`, why does Moviepy still display a progress bar?
How can I display a loading message in aggrid using react js?
How can Xcode 13.1 display the source code framework of an app?
How can I display the address field from the lead object in various sections?
Can AG-GRID display everything in a single column?
How can I modify Angular 8 to display a blank page without any error messages?
How can you display a Pandas Dataframe using a for loop?
How can the output of VBA be displayed in a cell within Excel?