When one serialize a model (table) which has relationship (ForeignKey) to other model, then you will only get the foreign_key, instead the whole object. Something like the following:
[ {
"pk": 1,
"model": "store.book",
"fields": {
"name": "Mostly Harmless",
"author": 42
}
} ]
In some cases, deep serializing is often necessary. Now, let me introduce you to this magnificent python module which extends django's built-in serializers. DjangoFullSerializers.
With this, you can get something like the following:
[ {
"pk": 1,
"model": "store.book",
"fields": {
"name": "Mostly Harmless",
"author": [ {
"pk": 42,
"model": "store.author",
"fields": {
"name": "John Doe",
"title": "Dr."
}
} ]
' }
} ]
I have used it and really satisfied with the result. Many thanks to the developer.
No comments:
Post a Comment