Well, then let me make sure I have all of this right.

My question was more general than a foreign key, but let's use the
Person and City idea. If on the Person list page I wanted to see City,
it would be no problem. I could just add 'city' to the list_display
tuple. However, when I sort on 'city' it will be sorting on the
foreign key, which as far as us users are concerned is completely
worthless.

The next question I have is that if the City model had an accompanying
state. Is there currently a way to display the state in the Person
model's list along with the city?

I can probably do something with the filter URL params as well. Do you
think it's a good idea to wait until the newforms admin is committed?


On Aug 24, 1:18 am, "Adrian Holovaty" <[EMAIL PROTECTED]> wrote:
> On 8/23/07, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
>
> > So my question is, is there a patch coming soon where we will be able
> > to include related fields of models in the admin columns as well as
> > search sort and filter on them? If not, is it a good idea for me to
> > start on functionality like this with the outstanding tickets
> > currently.
>
> Hi Trey,
>
> This is already possible. You asked two questions, so I'll answer both
> of them --
>
> To include related fields of models in change list columns, just
> include the foreign key in the "list_display" option:
>
>     class Person(models.Model):
>         name = models.CharField(max_length=100)
>         hometown = models.ForeignKey(City)
>
>         class Admin:
>             list_display = ('name', 'hometown')
>
> In this case, Django will follow the foreign-key relationship and
> display the value of the hometown's __unicode__() for each row.
>
> Note that we intentionally do not support many-to-many fields in
> list_display, because that would require a separate query for each
> row. But if you really want to do that, you can create a custom
> method. See the docs here:
>
> http://www.djangoproject.com/documentation/model-api/#list-display
>
> Regarding your second question, an admin-site feature that is
> relatively unknown is the fact that you can pass any valid filter()
> argument to the change list's query string. For example:
>
>    http://example.com/admin/myapp/poll/?id__lt=3
>
> There is no user interface for this, but that would be nice. If you're
> willing to contribute (which it sounds like you are), that'd be the
> area I'd suggest focusing on.
>
> Adrian
>
> --
> Adrian Holovaty
> holovaty.com | djangoproject.com


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to