Custom table name in Django model
If you want to map an existing table to a django model you have just to use the db_table property of the Meta class of your django model.
Here you have an easy example:
class User(models.Model):
class Meta:
db_table = 'my_user_table'
name = models.CharField(max_length=200)
surname = models.CharField(max_length=200)
In this example you can see how to map a django model class called User over a custom table called myusertable.
Written by Michele Capra
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#