[Django]-How to hide a field from the HTML form in the browsable Django Rest API?

0👍

I don’t have any info from your form, but DjangoForm has exclude property for that, you can access it viaself.exclude, also its type is a list, so you can append wanted field into that to exclude it

class Meta:
    model = Model
    exclude = ['field1', 'field2', ...]

0👍

item = Items.objects.get(pk=1).defer('field1')
serializer = MySerializer(item)

0👍

You can give only required fields in serializer class like this

class Meta:
        model = Model_name
        fields = (
            'id', 
            'field1',
            'field2'
        )

Leave a comment