I have a django model like this -
class Transaction(models.Model):
date = models.DateField()
type = models.IntegerField(choices=TRANSACTION_TYPE)
distributor = models.ForeignKey(Distributor)
second_party = models.CharField(max_length=100)
route = models.ForeignKey(DistributionRoute)
total_price = models.FloatField()
def __str__(self):
return self.date + " " + " " +self.total_price
I have tried to create a form from the model like this -
class transactionForm(forms.ModelForm):
class Meta:
model = Transaction
fields = ['date', 'type', 'distributor', 'second_party', 'route', 'total_price']
But i am constantly getting following error --
File "/home/itsd/sts/transaction/forms.py", line 5, in <module>
class transactionForm(forms.ModelForm):
File "/home/itsd/venv/lib/python3.5/site-packages/django/forms/models.py", line 247, in __new__
opts.field_classes)
File "/home/itsd/venv/lib/python3.5/site-packages/django/forms/models.py", line 133, in fields_for_model
opts = model._meta
AttributeError: 'tuple' object has no attribute '_meta'
I am stuck here for hours. What are the reasons for such issue ?
It's too late to answer this, but if someone ends up here. I want to share, I too faced the same problem. The issue sometime for this kind of error is a comma somewhere left unintentionally. And as a comma converts a python object to a tuple. This error occurs.
Suggestion in line:-
type = models.IntegerField(choices=TRANSACTION_TYPE)
Although type is not a reserved keyword in Python but still using type keyword will allow type() function in the scope of this class, so it is not a good practice.