Re: How to get ModelAdmin given a Model

2018-01-04 Thread Edouard C.
'type(v)' is model..instead of 'v is model' works, in case not too late for someone else... thanks Matt.. def get_admin(model): for k,v in admin.site._registry.iteritems(): if type(v) is model: return v On Monday, January 11, 2010 at 9:37:47 PM UTC, Matt Schinckel

Re: How to get ModelAdmin given a Model

2010-01-12 Thread Marco Rogers
I'm currently using the site._registry approach. I was hoping there was either a more "official" way. Incidentally, the registry is a dict so you should be able to access the model directly. from django.contrib import admin def get_admin(model): if model in admin.site._registry

Re: How to get ModelAdmin given a Model

2010-01-11 Thread Matt Schinckel
On Jan 12, 4:11 am, Tomasz Zieliński wrote: > On 11 Sty, 16:23, Marco Rogers wrote: > > > I'm reposting this from earlier to see if I have better luck. I need > > to be able to get the ModelAdmin associated with a model at runtime. > >

Re: How to get ModelAdmin given a Model

2010-01-11 Thread Tomasz Zieliński
On 11 Sty, 16:23, Marco Rogers wrote: > I'm reposting this from earlier to see if I have better luck. I need > to be able to get the ModelAdmin associated with a model at runtime. > Similar to how django.db.models.get_model allows you to retrieve a > model. > >    

How to get ModelAdmin given a Model

2010-01-11 Thread Marco Rogers
I'm reposting this from earlier to see if I have better luck. I need to be able to get the ModelAdmin associated with a model at runtime. Similar to how django.db.models.get_model allows you to retrieve a model. admin_class = get_admin(Model) Is this possible? The original post has more