Tuesday, April 4, 2017

ModelForm has no model class specified.

I have a form similar to that declared below:

 

class LineItemForm(Mixin, forms.ModelForm):

cost = forms.FloatField()

field_order = [‘part’, ‘cost’]

 

class Meta:

      model = LineItem

      fields = [‘part’]

 

And then I have another form that inherits from that:

 

class InventoryTransactionForm(LineItemForm):

      class Meta:

            fields = [‘part’, ‘document’]

            exclude = []

 

 

I have two views that use the InventoryTransactionForm.  View A uses it in a formset like so:

 

InventoryFormset = modelformset_factory(LineItem, InventoryTransactionForm, formset=InventoryTransactionFormSet)

inventory_formset = InventoryFormset(request.POST or None, initial=[{"part": default_part}])

 

View B uses just the form:

 

form = InventoryTransactionForm(

        request.POST or None, instance=inventorytransaction.transaction.lineitem, prefix="inventory", create_mode=False

    )

 

When I load View B, I get this exception:

ModelForm has no model class specified.

 

Everything works fine in View A.

Any ideas, thoughts, or suggestions?

Thank you,

Matthew

 

No comments:

Post a Comment