Django is an example of models.py

  • 2020-10-23 21:03:24
  • OfStack

From the command line, enter the Django project directory and execute


python manage.py inspectdb testmodel_test 

Where testmodel_test is the result generated by the data table


from django.db import models 
 
class TestmodelTest(models.Model): 
 name = models.CharField(max_length=20) 
 c1 = models.CharField(max_length=255, blank=True, null=True) 
 c2 = models.CharField(max_length=255, blank=True, null=True) 
 
 class Meta: 
 managed = False 
 db_table = 'testmodel_test' 

After modifying the class name, you can use it directly in models!


Related articles: