ok
these are the models i am trying to use i query them with po number which is passed as pk in the url
class po(models.Model):
uuid = models.UUIDField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
number = models.IntegerField(auto_created=True)
employee = models.ForeignKey(Employee, on_delete=models.CASCADE)
supplier = models.ForeignKey(Supplier, on_delete=models.CASCADE)
warehouse = models.ForeignKey(Warehouse, on_delete=models.CASCADE)
completed = models.BooleanField(default=False)
po_created_at = models.DateTimeField(auto_now_add=True)
class meta:
ordering = ['number']
def __str__(self):
return str(self.uuid)
class poItem(models.Model):
uuid = models.UUIDField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
item = models.ForeignKey(Item, on_delete=models.CASCADE, related_name='items1')
po = models.ForeignKey(po, on_delete=models.CASCADE, related_name='poitems')
required_quantity = models.IntegerField()
added_quantity = models.IntegerField(null=True, blank=True)
expiryDate = models.DateField(null=True, blank=True)
class meta:
ordering = ['item']
def __repr__(self):
return str(self.uuid)
i want to allow the user to input
added_quantity = models.IntegerField(null=True, blank=True)
expiryDate = models.DateField(null=True, blank=True)
while the rest of the values in poItem be displayed in the table and iterated through based on the number of items in each purchase order
poItem is the related name for the po in poItem class which refers to the po itself, the items are reffered to with related name items1 which returns
AttributeError at /PO-Detail/1/
'QuerySet' object has no attribute 'pk'
models.py
class poItem(models.Model):
uuid = models.UUIDField(primary_key=True,default=uuid.uuid4, editable=False, max_length=36)
item = models.ForeignKey(Item, on_delete=models.CASCADE, related_name='items1')
po = models.ForeignKey(po, on_delete=models.CASCADE, related_name='poitems')
updated code as per your last comment
ItemFormSet = inlineformset_factory(po, poItem, form=inflowForm, fields= ['added_quantity', 'expiryDate'])
orderNo = po.objects.get(number = pk)
orderItems = orderNo.poitems.all()
formset = ItemFormSet(instance=orderItems)
if request.method == "POST":
formset = ItemFormSet(request.POST, instance=orderItems)
if formset.is_valid():
formset.save(commit=False)
for instance in formset:
instance.save()