Задать вопрос

Тел: +7 965 3737 888

674

Просмотров

6

Ответов

Link raw_id_fields (both ForeignKeys and ManyToManyFields) to their change pages

UPDATE: Now works in Django 1.4

Based on luc_j:s snippet (http://djangosnippets.org/snippets/2108/) to show values in ManyToManyFields in the admin. This snippets does that, but also links each value to its corresponding admin change page.

To use, just set the raw_id_fields to the value you want, and let your form inherit from ImproveRawIdFieldsForm.

Вопрос полезен? Да0/Нет0
file_3856.py(2.3Кб)
None

Ответы (6):

Ответrwmcfa1:08.08.2014
Ответ полезен? Да0/Нет0

if you change line 45 to the follow it will also support OneToOneRel's

if type in ('ManyToOneRel', 'OneToOneRel'):

also a good ideal to add the following else after line 48 to avoid losing special handling in super's formfield_for_dbfield for raw_id_fields we don't otherwise handle (assuming there's more than 3 types)

else:
    # we don't have anything special for this type
    return super(ImproveRawIdFieldsForm, self).formfield_for_dbfield(db_field, **kwargs)

Ответkase:11.08.2013
Ответ полезен? Да0/Нет0

so... how i use in INLINE form?

Ответemilstenstrom:12.02.2013
Ответ полезен? Да0/Нет0

@AndyHilton: Here's some example usage: https://gist.github.com/EmilStenstrom/4761449

Ответandyhilton:29.12.2012
Ответ полезен? Да0/Нет0

This sounds like just what I am looking for but struggling to see where to put the pieces (as with so many django snippets it's hard when it is just raw code without a note to say where it should be placed !) - I tried adding the above to my admin.py but cannot then see how to inherit my form from ImproveRawIdFieldsForm (my form is currently in forms.py) - am sure I am close !! Any helpful pointers ?

Ответemilstenstrom:25.04.2012
Ответ полезен? Да0/Нет0

Updated to work in Django 1.4.

Ответcerinin:26.02.2012
Ответ полезен? Да0/Нет0

Thanks, works perfectly! I can't imagine why this functionality isn't included by default!