Wednesday, May 27, 2015

Re: How to pass a queryset for each different field Admin Inlines

From what I could understand, you want to change the options of the "value options" field depending on the selected "attribute".
Since the choosing of the "attribute" happens in the frontend and there's no page refresh, the backend does not know about it, and therefore cannot filter the "value options".
For this to work, you will need to write some javascript code to perform the filtering in the browser after the attribute is choosen.
It can also be achived with a ajax call.
Either way, not the easiest to do in django admin.

Someone can help me ?, he took days trying to fix this and nothing to get it, if I could just iterate a QuerySet each model choice of the form. The only thing achieved is that a queryset applies to all forms inline, but I need a different one for each inline.
    def formfield_for_foreignkey(self, db_field, request, **kwargs):
        if db_field.name == "value_option":
            kwargs["queryset"] = request._obj_.category.attributes.all()
        return super(AttributeInline, self).formfield_for_foreignkey(db_field, request, **kwargs)


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/50459949-79eb-4452-b6b9-386517669525%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAA-QWB1gW8NXSWK2UVjrHg9cAx5ugMQJD5M69m%2BDggTuaA8NKw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment