While using django.forms.inlineformset_factory is there a way to keep track of line numbers and pass that information to the model?
For example, consider the following in models.py
class BillLine(models.Model):
parent = models.ForeignKey(BillHeader, on_delete=models.CASCADE)
description = models.TextField(default = "stuff")
quantity = models.IntegerField()
unit_price = models.DecimalField(decimal_places = 2)
line_number = models.IntegerField(default=0)
and the following in forms.py
class BillHeaderForm(ModelForm):
class Meta:
model = BillHeader
fields = '__all__'
class BillLineForm(ModelForm):
class Meta:
model = BillLine
fields = ('description', 'quantity', 'unit_price') # line number not included
BillLineFormSet = inlineformset_factory(BillHeader, BillLine, fields = ('description', 'quantity', 'unit_price'), form = BillLineForm)
When BillLineFormSet is rendered onto the view, how would I go about keeping track of line numbers?