On Wed, Feb 2, 2011 at 5:39 PM, Marc Aymerich <glicer...@gmail.com> wrote:
> On Wed, Feb 2, 2011 at 5:19 PM, Daniel Roseman <dan...@roseman.org.uk> wrote:
>> 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.
>
>
> Hi Daniel, and thanks for your answer!. The admin.inlines has a method
> called insert, so some dejango developer(s) is concerned about
> inserting inlines in that way.
>
> inlines.insert(...)
>    L.insert(index, object) -- insert object before index
>
> Actually I take the idea from Satchmo project source. Any way, and as
> you say, if an inlines is overrided everything works great :)
>
> I add an inlines = [] into my VirtualHostAdmin class and now the code
> that I post in my first email works fine.
>


Oh, the reason for I want to insert inlines in that way is because I'm
developing a reusable app for control apache server through django
admin. So i split the PHP support for apache in a separated app, so if
you uses my app and you want PHP support, you need to explicit install
the "php app" and only then you get the PHPVersionInline and
VirtualHostPHPOptionInline inlines into VirtualHostAdmin. In that way
all PHP support related code lives on php app.


-- 
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