On Wednesday, February 2, 2011 4:00:34 PM UTC, Marc Aymerich wrote: > > Hi! > I have a plugin style app that adds "support" for PHP (inserting two > admin inlines) into VirtualHostAdmin class, I use this code for the > job: > > admin.site.unregister(VirtualHost) > ix = len(VirtualHostAdmin.inlines) > VirtualHostAdmin.inlines.insert(ix, PHPVersionInline) > VirtualHostAdmin.inlines.insert(ix+1, VirtualHostPHPOptionInline) > admin.site.register(VirtualHost, VirtualHostAdmin) > > I don't know why but this inserts the PHPVersionInline and > VirtualHostPHPOptionInline into ALL of my admin models without an > admin inline defined. For example: > > print "admin model who haven't nothing to do with VirtualHost and have > NO inlines" > [<class 'ucp.php.admin.PHPVersionInline'>, <class > 'ucp.php.admin.VirtualHostPHPOptionInline'>] > > print "admin model who haven't nothing to do with VirtualHost and have > inlines defined" > [<class 'ucp.pricing.admin.RateInline'>] > > consequently, when I try to load a change_forma for > ucp.pricing.models.Pack django servers raise this exeption: > <class 'ucp.php.models.PHPVersion'> has no ForeignKey to <class > 'ucp.pricing.models.Pack'> > > Any clue about what's going on here? > > Thanks! > -- > Marc >
Have a look at the code for the ModelAdmin class in django.contrib.admin.options. The `inlines` attribute` is defined at class level. That means it is shared by all instances of ModelAdmin, unless overridden in a subclass. Now, strictly speaking this is probably a bug, in that this shouldn't happen. However, you're hacking around with the inlines in a very very non-standard way, so I wouldn't be surprised if it never gets fixed. A quick fix would be to always be sure to create a new list: inlines = VirtualHostAdmin.inlines or [] inlines.append(PHPVersionInline) inlines.append(VirtualHostPHPOptionInline) -- DR. -- 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.