On Fri, Jul 15, 2011 at 1:35 PM, Marc Aymerich <glicer...@gmail.com> wrote:

> Hi,
> I created a method that generates an InlineFormset at runtime and inserts
> it to a given ModelAdmin.
>
> It works perfectly when I call my method directly on admin.py
> #admin.py
> admin.site.register(MyModel, MyModelAdmin)
> insert_generic_plugin_inlines(MyOtherModelAdmin)
>
> but it doesn't work when this method is called for example on a post_save
> signal. Actually, in this scenario, the Inlineformset is created and
> inserted to MyOtherModelAdmin.inlines, but admin interface never show it.
>
> This is how my method performs the inline insert:
>     admin.site.unregister(model)
>     ix = len(model_admin.inlines)
>     model_admin.inlines.insert(ix+1, inline)
>     admin.site.register(model, model_admin)
>
> Why the admin interface displays the inline formset when the method is
> called during an admin.py import but not when it's called later? Any idea?
>


I think it's something related to that admin.site.unregister(model)
and admin.site.register(model, model_admin) doesn't truly swap the
ModelAdmin site, because I get two different MyModelAdmin objects if I query
the admin.site._registry[model] compared to print "self" on the
ModelAdmin.add_view()

# on my method
print admin.site._registry[model]
<my_app.admin.MyModelAdmin object at 0x3e0ed10>

#on ModelAdmin.add_view()
print self
<my_app.admin.MyModelAdmin object at 0x3ed4b40>

what I have to do to truly change the modeladmin at runtime ?

-- 
Marc

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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