user1667957
user1667957

Reputation: 81

How to create field name in django models with hyphen?

I have table with name of column "call-limit".

When create field in django models:

   call-limit = models.IntegerField(default=1,verbose_name='call-limit')

I have error.

Thank you for help

Upvotes: 1

Views: 1511

Answers (1)

xnx
xnx

Reputation: 25560

You can set or refer to the name of the column in your relational database from the model with the db_column argument:

call_limit = models.IntegerField(default=1, db_column='call-limit',
                                 verbose_name='call-limit')

But the model name in your Python code must be a valid Python identifier, so cannot contain the hyphen. Why not use call_limit instead?

See the docs for more information.

Upvotes: 4

Related Questions