S
S
S0ulReaver2012-04-25 18:59:16
Django
S0ulReaver, 2012-04-25 18:59:16

Django: search in admin by ForeignKey?

In general, I faced such a problem. There is a certain model, with a couple of fields. There is one big model where one of the fields is this little model bound as a ForeignKey. Everything would be fine, but it is impossible to search by these fields in the admin panel (if you add them to search_fields, an error occurs when you try to search). Also, there is no way to organize filtering on them - if you add them to list_filter, then the elements for the filter simply do not appear in the menu on the right - as if they are not in list_filter at all. I'm using admin_tools and Django 1.4. Are there any options for getting out of the situation?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
scream4ik, 2012-04-25
@scream4ik

Custom page
You write your own view, catch id, make a selection and transfer it to a custom template. I did this using django-grappelli. I redefined the template from grappelli, added my own cycle. Came out like a native

S
scream4ik, 2012-04-25
@scream4ik

via search_fields is a bad option. For example, you need to make a selection with id 1, it will make a selection for you where else and id 11 and 101, etc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question