[Answered ]-'QuerySet' object has no attribute ' – Django ORM issue

1πŸ‘

βœ…

The uom_binuom_set is for a single UOM instance

UOM.objects.get(pk=1).uom_binuom_set.all()

However, you have UOM_BINUOM.objects.filter(...), which is a queryset. As the error says, the queryset does not have the uom_binuom_set method.

You can construct the queryset you want by starting with the UOM_BINUOM model.

uombinuom = UOM_BINUOM.objects.filter(UOM__material=material_id)

Note that since material_id is a single id, you don’t need to use __in.

πŸ‘€Alasdair

1πŸ‘

When you do

uom = material.uom_set.all().order_by('-id')

uom is a QuerySet here. uom_binuom_set should be called on single record not QuerySet of records.
So you will need to iterate over the uom QuerySet and call .uom_binuom_set.all() for each record.

for record in uom:
   uom_binuom =  record.uom_binuom_set.all()
   # do something with uom_binuom

Or if you want only first records related uom_binuom then

uom_binuom = uom.first().uom_binuom_set.all()

Leave a comment