The Django Admin Action documentation leads you through exporting a queryset to JSON. However exporting from a single model rarely tells the whole story.
Using the CollectObjects class,
export_related_as_json gathers all instances related by foreign keys to what is being exported and exports them as well in a serialization bonanza.
Use it to export Users and you'll get their Profile objects as well!
# admin.py from django.contrib import admin admin.site.add_action(export_related_as_json)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
More like this
- Serializer factory with Django Rest Framework by julio 3 months, 1 week ago
- Image compression before saving the new model / work with JPG, PNG by Schleidens 4 months ago
- Help text hyperlinks by sa2812 4 months, 3 weeks ago
- Stuff by NixonDash 7 months ago
- Add custom fields to the built-in Group model by jmoppel 9 months, 1 week ago