Display related foreign key values in Admin - but not inline

4 views
Skip to first unread message

orestis

unread,
Oct 11, 2006, 11:40:11 AM10/11/06
to Django users
Hello, I have a model of EnglishWords and GreekWords. EnglishWords are
referenced as a ForeignKey in GreekWords, ie one EnglishWord may have
more than one GreekWords referencing it.

I would like when going in admin to edit an EnglishWord to see what
Greek words are referencing it, and be able to click on each GreekWord
and go to its edit page.

If I use edit_inline, I suppose I'll get a huge select box of all the
GreekWords there, and I don't want that.

Thanks!

Malcolm Tredinnick

unread,
Oct 11, 2006, 9:39:53 PM10/11/06
to django...@googlegroups.com

The admin page does not operate in the way you want. You will need to do
some deep customisation in order to make that happen. There's been some
discussion on this list recently about how to customise the appearance
of various pages. You will also possibly have to write your own template
tags here, too. Not impossible if you approach with the right mindset,
but it's not "out of the box".

Regards,
Malcolm


patrickk

unread,
Oct 12, 2006, 4:25:22 AM10/12/06
to django...@googlegroups.com
if I´m not mistaken, what malcolm described is not too hard to achieve.

### copy the change_form.html to you personal admin-directory
### change the change_form: add something like {% ShowGreekWords
object_id %}
### GreekWords is a templatetag which might look like:
from django.template import Library
register = Library()

def ShowGreekWords(object_id):
from app.words.models import GreekWord

greek_words_list = GreekWord.objects.filter(englishword=object_id)

return {
'greek_words': greek_words_list,
}

register.inclusion_tag('admin/tag_container/list_greekwords.html')
(ShowGreekWords )

### finally, you have to write the template mentioned above (which is
probably a list of greek words linked to its edit page)

patrick

orestis

unread,
Oct 12, 2006, 5:18:45 AM10/12/06
to Django users
Thanks! I'll try that and get back here...

Reply all
Reply to author
Forward
0 new messages