Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

522
Views
Django form AttributeError: 'tuple' object has no attribute '_meta'

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 ?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

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.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!