Tuesday, May 26, 2015

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

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.

No comments:

Post a Comment