[Fixed]-How to Serialize BigIntegerField, TextField in serializer Django

35👍

This is because the django rest framework’s Serializer doesn’t have a TextField. Where your model has a TextField you need to use a CharField in the serializer.

CharField A text representation. Optionally validates the text to be
shorter than max_length and longer than min_length.

Corresponds to django.db.models.fields.CharField or
django.db.models.fields.TextField.

The documentation isn’t as clear about BigIntegerFields from models, but this line for the source code shows that IntegerField is again what you have to use in the serializer.

👤e4c5

5👍

For text field you can follow the following convention

your_variable_name = serializers.CharField(style={'base_template': 'textarea.html'})

Suggested in rest framework documentation.

1👍

Replace TextField with CharField. Both have basically the same functionality, but serializers understand only the later.

Leave a comment