I have a django app (using the django-rest-framework) that needs to serialize and deserialize JSON payloads with the python keyword "import" as one of the fields. To prevent conflicts in the model, I can call the field import_flag and use the source option in the ModelSerializer.
models.py
class MyModel(model.Model):
import_flag = models.BooleanField(verbose_name='Import')
But (for obvious reasons) I cannot use the import keyword as to create a JSON field named "import" like so.
serializers.py
class MyModelSerializer(serializer.ModelSerializer):
import = serializers.BooleanField(source='import_flag')
def Meta:
model = MyModel
This field is present in the JSON I consume from a third-party's RESTful API and I also need to serialize it and send it back to the same third-party.
Is there something like a destination option for the Django-rest-framework ModelSerializer class? I have been unable to find anything in the documentation.