How can i used column named class in django?

Viewed 30

I need use column named class. But class is a keyword reserved in python.

models.py:

class Colecao(models.Model):
       class = models.CharField(max_length=50,blank=True,verbose_name="Classe")
1 Answers

By default, Django will use the field’s name as the name of the database column . in your case class is a reserved keyword in python you cannot use it but you can customize the database column name for it by using db_column use it like this :

class Colecao(models.Model):
       class_ = models.CharField(max_length=50,blank=True,
         db_column='class', verbose_name="Classe")
Related