Django
Loading initial data (fixtures)
When running syncdb, it spitted out this error message:- ValueError: No JSON object could be decoded
Turn out the error in the json initial data file:-
[
{
"pk": 1,
"model": "auth.user",
},
{
"pk": 1,
"model": "app.profile",
},
]Notice the trailing comma ',' after the second object ?
Custom views / object actions in admin
I want something like "History" button in the object edit form (change_form). Adding the button already covered in the docs but what not clear how to add my custom views that can operate on that object.
Override method get_urls in ModelAdmin subclass.
but accessing the page as /admin/myapp/withdrawal/2/receipt/ return 404 page saying u"2/receipt" primary key not exists. So the admin app took 2/receipt as the object id instead of just 2 when try to load the object. This also mean even though I placed my custom urls first, the admin app still executing the edit form views. We need to override the ModelAdmin.change_form method:-
The closest I found on stackoverflow:- [[http://stackoverflow.com/questions/2805701/is-there-a-way-to-get-custom-django-admin-actions-to-appear-on-the-change-view]]
Accessing object being edited in admin change_form template
[[http://stackoverflow.com/questions/4635548/accessing-the-object-in-a-django-admin-template]]
Last updated
Was this helpful?