You should be able to customize the queryset of any form by overriding it in 
the init method of the form. In this case, it's a little trickier because 
you'll need a custom admin and custom form for the inline. I haven't been able 
to test this, but I think you'll need to do the following. 

In forms.py, add a custom inline form, and in the init method customize the 
queryset to whatever it needs to be, after calling super, e.g.:

class OrderRowsInlineForm(forms.ModelForm):
    class Meta:
        model = None
        fields = '__all__'
    
    def __init__(self, *args, **kwargs):
        super(OrderRowsInlineForm, self).__init__(*args, **kwargs)
        self.fields['product'].queryset = 
Product.objects.filter(brand='whatever')


Then in admin.py, import the form and add a custom admin for the inline that 
uses that custom form, like:

from forms import OrderRowsInlineForm

class OrderRowsInline(admin.TabularInline):
    model = OrderRows
    form = OrderRowsInlineForm


Now, depending on what you want to set the queryset to, you might run into some 
trouble; if the list of brands for an order row depends on the brand in the 
product, you might have to do some trickery to pass the proper brand (or brand 
id) down into the form. You can generally use self.instance, but if these are 
new records that haven't been saved yet (i.e. the user will be filling in the 
details and clicking Save), which i assume is true, then i believe 
self.instance is None until saved, so won't be useful here. 

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/289175e1-c741-464f-bb25-66c9809e1cc6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to