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
            return admin.site._registry[model]
        return None

I haven't testing this because I'm doing something slightly different

:Marco

On Jan 11, 4:37 pm, Matt Schinckel <matt.schinc...@gmail.com> wrote:
> On Jan 12, 4:11 am, Tomasz Zieliñski
>
>
>
> <tomasz.zielin...@pyconsultant.eu> wrote:
> > On 11 Sty, 16:23, Marco Rogers <marco.rog...@gmail.com> 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.
>
> > >     admin_class = get_admin(Model)
>
> > > Is this possible?
>
> > > The original post has more info.
>
> > >http://groups.google.com/group/django-users/browse_thread/thread/0cd0...
>
> > Maybe something like this:
>
> > 1. Write something like django.contrib.admin.autodiscover, to get all
> > ModelAdmins
> > 2. Iterate those ModelAdmins, retrieve models they are attached to and
> > store this mapping in a dict.
> > 3. def get_admin(model):
> >         return admin_to_model[model]
>
> You should be able to iterate through admin.site._registry, and pull
> out the one you need.
>
> from django.contrib import admin
> def get_admin(model):
>     for k,v in admin.site._registry.iteritems():
>         if v is model:
>             return v
>
> Written in a browser.
>
> Matt.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to