I'm trying to find a solution to this very same issue.  At the very
least, I think inlines should support custom callables.

The inline I'm displaying is an intermediary table for a ManyToMany
relationship. So I have a selector for the related object, but what I
would like to do in the inline is also display a few of the fields on
the related object.  Take this (truncated) example.

class Group
   status = Char

class Member
    groups = ManyToMany through Membership
    member_since = Date

class Membership
    group = ForeignKey
    member = ForeignKey
    order = Integer

class MembershipInline
    model = Membership

The membership inline works just fine for the primary goal of ordering
the members in the Group.  But it would be a nice visual aid to be
able to display the member_since date in the inline.  This is good
information to inform the ordering.  Right now I can't find a way to
do this other than denormalizing and copying the member_since field
onto the Membership Model.  What I would expect is to be able to do is
something like this.

class MembershipInline
    model = Membership
    list_display = ('member_since',)

    def member_since(self, obj):
          return obj.member.member_since.strftime()
    member_since.short_description()



On Jan 7, 5:32 am, frans <franshaar...@gmail.com> wrote:
> On 7 jan, 11:15, Daniel Roseman <dan...@roseman.org.uk> wrote:
>
>
>
> > On Jan 7, 9:22 am, frans <franshaar...@gmail.com> wrote:
>
> > > Is this something which exists ? Looking at Tabular/Stacked Inline
> > > features I think not.
> > > So then, I assume I want a Pony , however, I think many people want
> > > this pony so its probably impossible to re-use thelist_display
> > > functionality forinlines?
>
> > > It be very nice though. Hopefully someone could point me to some
> > > snippets or clue-bat me why its impossible/where I should start
> > > extending :)
>
> > > Thanks,
> > > Frans
>
> > How would you want this to work? The normal way to show related items
> > in the changelist is to define a custom method which returns the list
> > - eg ','.join([o.name for o in obj.related_set.all()])
>
> > Does that not work for you?
>
> That works.  I am using that also to create "clickable" columns in 
> thelist_displayby setting "safetags" and putting the <A HREF> code in
> the results.
>
> However I dont think I was clear enough about what I am trying to
> accomplish.
> Basicly, I would like a "DisplayInline"  admin model. Which renders
> theinlinessimilar as the admin does on models withlist_display
> fields set.
> currently it renders the editable columns. And gives me a small header
> for each row.
>
> I was hoping it somehow already existed or could re-use 
> thelist_displayfunctionality in the inline somehow.  But perhaps I need
> to actually build
> some sort of "DisplayInline" based on TabularInline or something.
-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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