Skip to content

ModelSerializer requiring fields set to blank/null=True in the Model. (DRF3) #2017

@jarrodb

Description

@jarrodb

Just verifying this was an intended change from 2.4 -> 3.0 that now requires specifying a null value for resource creation when Model fields contains blank=True and null=True (without default=) since the ORM will handle it:

models.py

class Test(models.Model):                                                       
    name = models.CharField(max_length=255)                                     
    description = models.TextField(blank=True, null=True)
class TestSerializer(serializers.HyperlinkedModelSerializer):                   
    class Meta:                                                                 
        model = Test                                                            
        fields = ('url', 'name', 'description')                                 


class TestViewSet(viewsets.ModelViewSet):                                       
    queryset = Test.objects.all()                                               
    serializer_class = TestSerializer    
(drf30)$ curl -H 'Accept: application/json; indent=4' -X POST -d "name=whatsup" http://127.0.0.1:8000/tests/ 
{
    "description": [
        "This field is required."
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy