'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 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 unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/8f5d1af4-3792-44f6-b8a4-f0fc1dbf8b6d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to