Thank you Peter.

But list_display does not get used on the edit page of an object.

If you use raw_id the ID of the foreign key gets displayed right to the
input field. It would be nice to make it a hyperlink.

  HTH,
    Thomas

Peter Bengtsson schrieb:
> 
> 
> On 3 Aug, 10:12, Thomas Guettler <h...@tbz-pariv.de> wrote:
>> Hi,
>>
>> How can I display a link to the edit page of a foreign key?
>>
>> Example:
>>
>> class Place:
>>     city=models.ForeignKey(City)
>>
>> In the admin page of the place I want a link to the city admin page.
>>
> 
> class PlaceAdmin(admin.ModelAdmin):
>     list_display = ('city_special',)
>     def city_special(self, obj):
>          return '<a href="/admin/cities/city/%d/">%s</a>' % \
>           (obj.id, obj.name)
>     city_special.short_description = u'City'
>     city_special.allow_tags = True
> 
> That should get you started. I don't know if there is a more correct
> way to get the admin edit url for an object.


-- 
Thomas Guettler, http://www.thomas-guettler.de/
E-Mail: guettli (*) thomas-guettler + de

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