Django formset queryset

I have two apps: accounting and projects.

Every consumption item has a fk to project.
Every production has a fk to a project.

Production order has fk to production.
produced product has fk to production order.
consumption item has fk to produced product.

While creating produced line, I want to create consumption line as formset. However, consumptionitemline_to_consume field should show instances from the related project, not all instances.. Below I tried to filter the dropdown however, it just does not work.

here is forms

class ProductionProducedLineConsumptionLineForm(forms.ModelForm):
    class Meta:
        model = ProductionProducedLineConsumptionLine
        fields = '__all__'
        widgets = {
            'productionproducedline': forms.HiddenInput(),
            'produced_kg_scrap': forms.NumberInput(attrs={'class': 'w-full input rounded-md'}),
            'produced_kg_wastage': forms.NumberInput(attrs={'class': 'w-full input rounded-md'}),
        }

    def __init__(self, *args, **kwargs):
        production_id = kwargs.pop('production_id', None)  # We'll pass this when initializing the formset in the view
        super(ProductionProducedLineConsumptionLineForm, self).__init__(*args, **kwargs)
        if production_id:
            production = ProductionProducedLine.objects.get(id=production_id)
            project = production.productionorderline.production.project
            self.fields['consumptionitemline_to_consume'].queryset = ConsumptionItemLine.objects.filter(project=project) # This does not work?


ProductionProducedLineConsumptionLineFormSet = inlineformset_factory(
    ProductionProducedLine,
    ProductionProducedLineConsumptionLine,
    fk_name='productionproducedline',
    form=ProductionProducedLineConsumptionLineForm,  # Use the custom form
    fields=('productionproducedline','productionproducedline_to_consume', 'consumptionitemline_to_consume','consumed_kg_product','produced_kg_scrap', 'produced_kg_wastage','wastage_return_customer'),
    extra=1,
    can_delete=True
)


Here is view


class ProductionProducedLineCreateView(CreateView):
    model = ProductionProducedLine
    form_class = ProductionProducedLineForm
    template_name = 'projects/produced_create.html'


    def get_form_kwargs(self):
        """Ensure the form is initialized with necessary kwargs."""
        kwargs = super(ProductionProducedLineCreateView, self).get_form_kwargs()
        if self.kwargs.get('order_line_id'):
            kwargs['order_line_id'] = self.kwargs['order_line_id']
        return kwargs

    def get_context_data(self, **kwargs):
        """Add formset to context data for rendering in the template."""
        context = super(ProductionProducedLineCreateView, self).get_context_data(**kwargs)
        order_line_id = self.kwargs.get('order_line_id')
        if order_line_id:
            order_line = ProductionOrderLine.objects.get(pk=order_line_id)
            context['order_line'] = order_line
            context['production'] = order_line.production
            context['project'] = order_line.production.project
            if self.request.POST:
                context['formset'] = ProductionProducedLineConsumptionLineFormSet(self.request.POST, self.request.FILES)
            else:
                context['formset'] = ProductionProducedLineConsumptionLineFormSet()
        return context

    def post(self, request, *args, **kwargs):
        """Handle POST requests: Validate both form and formset."""
        self.object = None  # This is required for CreateView to correctly instantiate the form
        form = self.get_form()
        formset = ProductionProducedLineConsumptionLineFormSet(self.request.POST, self.request.FILES)
        if form.is_valid() and formset.is_valid():
            return self.form_valid(form, formset)
        else:
            return self.form_invalid(form, formset)

    def form_valid(self, form, formset):
        """If the form and formset are valid, save the associated models."""
        self.object = form.save()  # Save the ProductionProducedLine instance
        formset.instance = self.object  # Link the formset with the instance
        formset.save()  # Save the formset data
        return redirect(self.get_success_url())  # Redirect to a success page

    def form_invalid(self, form, formset):
        return self.render_to_response(self.get_context_data(form=form, formset=formset))

    def get_success_url(self):
        """Return the URL to redirect to after successful processing."""
        # Adjust this to wherever you want users to be redirected after a successful creation
        return reverse('production-list')

I just lost. Any help is appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật