Overriding a Django admin.ModelAdmin function for all models


Overriding a Django admin.ModelAdmin function for all models



I'm sort of stitching together contrib.databrowse (to view) and contrib.admin (to edit), and I'd like to override the *response_change* function in admin.ModelAdmin so that when you click save, it redirects back to the object in databrowse rather than the admin. I know how to do this for a specific model in admin.py, like:

class WhateverAdmin(admin.ModelAdmin):     def response_change(self, request, obj):         # stuff  admin.site.register(Whatever, WhateverAdmin) 

but I'd like to apply that to all of my models without just copying the function over and over (i.e. override it in admin.ModelAdmin itself). Where and how should I do that?

Thanks. :)




How do I read a Django HTTPResponse in Flex?

1:



What's the best way to “embed” a page number in a URL?
You could have your admin classes inherit off of the WhateverAdmin class..
Is it dangerous to leave your Django admin directory under the default url of admin?
So for example, your app is laid out as....
X-Requested-With/HTTP_X_REQUESTED_WITH weird problem
\site_defaults     __init__.py     admin.py \your_app_1     __init__.py      models.py      admin.py \your_app_2     __init__.py      models.py      admin.py 
For the 2 apps you have, in the admin.py the code would be like....
Alternate Row Coloring in Django Template with More Than One Set of Rows
from site_defaults.admin import WhateverAdmin  class YourApp1Admin(WhateverAdmin):  # << note it's not admin.ModelAdmin     # code over here 


Django ORM: Get most recent prior object that meets a certain condition


How can I deploy a django appserver as an egg, running behind fastcgi?

2:



How can I get Django to output bad characters instead of returning an error
Here's my solution thanks to T.

Stone's Idea
.. I didn't think to register each model with the same Admin class if I wasn't changing anything else.

The ones that need special changes inherit the new class, the rest call admin.site.register with it: .
class MyModelAdmin(admin.ModelAdmin):     def response_change(self, request, obj):         # code   class SomethingAdmin(MyModelAdmin):      # code specific to the Something model   admin.site.register(Something, SomethingAdmin) admin.site.register(Another, MyModelAdmin)  admin.site.register(OneMore, MyModelAdmin) 



85 out of 100 based on 85 user ratings 985 reviews

@