Open nnseva opened 13 years ago
Ok, yeah what you need to do is, define the fields property on the admin for the BottomInline. You should only include the foreign key. In your case it should look like:
class BottomInline(LinkInline):
model = models.Bottom
fields = ('top',)
The parent_link should not be used in the BottomInline, only in the BottomAdmin. http://packages.python.org/django-easymode/tree/api.html#easymode.tree.admin.abstract.LinkInline I don;t know why the fields are empty. That is a bug. Please try again with the definition of BottomInline as follows:
class BottomInline(LinkInline):
model = models.Bottom
fields = ('top', 'text')
But again, you should not show the fields in that form, only the links should be visible. So only the foreign key should be in fields
The documentation also says you MUST define the fields property
class BottomLinkInline(LinkInline):
"""
This is the inline view of the inlined item. It will de rendered as a
link to the change view or add view of the inlined item.
NOTE that you MUST define fields, which must only include the foreign key.
Ofcourse you might want to include some more fields and put them as
read_only_fields, to give a bit more info.
"""
fields = ('top',)
model = BottomModel
Explicit definition of the 'fields' property doesn't help.
Definitely, the BottomInline works as described if I include the only 'top' field (foreign key) to the 'fields' property, but this is not an expected behaviour for the inline form inherited from the standard django inline :(
Really I wanted to have a standard django inline (probably readonly) with additional link to the full-featured (sub)object editor. The str() representation of the (sub)object helps partially, but is not a complete solution if I f.e. wanted to have a table of (sub)object rows. I will think about it ...
If you add 'text' to readonly_fields does that work? Or is it still empty?
class BottomInline(LinkInline): model = models.Bottom fields = ('top', ) readonly_fields = ('text',)
It doesn't work (the 'text' is not shown at all) in this form, but the following is working as expected:
class BottomInline(LinkInline):
model = models.Bottom
parent_link = 'top'
fields = ('top','text')
readonly_fields = ('text',)
Ok so the documentation should be updated to reflect this.
It might be useful to have a separate object like 'object link widget' which I can add to the standard (or inherited from standard) tabular or stacked inline ... this solution will cover all needs.
Hmm the problem is, that django overrides every attempt to have a custom widget for a the foreign key field in inlines. That is why LinkInline has a custom formset, to stop django from resetting it to it's default.
So what you are proposing is not possible. You always have to override the formset. Maybe what you want is what I'm doing in: https://github.com/specialunderwear/django-polymorphic-easymode/blob/master/mixed/admin.py
It also renders a link to the 'full' admin.
Hmm ... it is really near to my needs, including polymorphing, I should investigate it deeply ...
For some reason, the LinkInline doesn't show inline objects except the first one.
I've created a very simple example with two models:
and created a simple admin for them:
The first (uncommented) portion of the admin is working with easymode, while the second one (commented out) is a standard django admin code.
I am filling in one Top object and several Bottom objects linked to the Top one. When I am looking to the standard admin, I see several filled objects: https://docs.google.com/open?id=0B6V0N4fDeXFPNjJjZGExMDMtNjk5Yi00NzZiLWE2MjctZDVjNjE5OWRlNDM4
When I am looking to the easymode-powered admin, I see the only one Bottom object filled, but several object lines with links (links are working): https://docs.google.com/open?id=0B6V0N4fDeXFPYzM5MGZlMGItNjExYi00MGRhLTkwMjUtYjEwZDViZGEwNTU5