[Answered ]-How can get the data from the foreign key in django

1👍

You filter with:

class All_Vendor(TemplateView):
    template_name = 'purchase/allVendor.html'

    def get(self, request, *args, **kwargs):
        categories = categoryModel.objects.all()
        categoryId = self.request.GET.get('SelectCategory')
        vendors = Vendor.objects.filter(
            vendorcategory__category_id=categoryId
        )
        args = {'categories': categories, 'selectedCategory': categoryId, 'vendors': vendors}
        return render(request, self.template_name, args)

vendorselect makes not much sense, since that is a collection of VendorCategorys, not Vendors.

Leave a comment