On Mon, Jun 21, 2010 at 4:37 AM, Massimiliano della Rovere <
[email protected]> wrote:
> Anyway, my idea is the following:
> reference fields shown in the change list page (not change view) shown
> as links to the edit page of the instance.
> I tried to implement this on my own, specifying in display_list the
> name of an executable returning a link to the change page and settings
> executable.allow_tags = True, but doing so one cannot put this field
> in the list_filter tuple.
>
>
? You cannot put the callable you specify in list_display in list_filter,
but you can put the ForeignKey field itself. For example I have a model:
class FosterHome(models.Model):
name = models.CharField(max_length=64, unique=True)
caretaker = models.ForeignKey(Caretaker)
def caretaker_admin_link(self):
return u'<a href="%s">%s</a>' % (reverse(
'admin:ctrac_caretaker_change', args=(self.caretaker.pk,)),
unicode(self.caretaker))
caretaker_admin_link.short_description = 'Caretaker'
caretaker_admin_link.allow_tags = True
[other stuff snipped]
With admin definition:
class FosterHomeAdmin(admin.ModelAdmin):
list_display = ('name', 'caretaker_admin_link', 'count_foster_cats',
'best_phone', 'best_email')
search_fields = ('name', 'caretaker__name', 'cat__name')
list_filter = ('caretaker', )
inlines = [InlineFosterCat]
With this admin definition the Caretaker column in the change list page for
Foster Homes shows links to the edit page for the related Caretakers, and
there is a working "By Caretaker" filter on the right.
Given what you ask for seems to be easily implemented by existing admin
customization hooks I don't see the need for adding anything directly into
admin to support this.
Karen
--
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en.