Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

514
Vistas
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 ?

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

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.

about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda