Tuesday, June 19, 2007

如何根据已有数据自动产生Model

使用方法非常简单:
在项目目录下的命令行中输入:
python manage.py inspectdb

python manage.py inspectdb > models.py

自动产生models.py文件:

python 代码
  1. class DjangoAdminLog(models.Model):
  2. id = models.IntegerField(primary_key=True)
  3. action_time = models.DateTimeField()
  4. user_id = models.IntegerField()
  5. content_type_id = models.IntegerField(null=True, blank=True)
  6. object_id = models.TextField(blank=True)
  7. object_repr = models.CharField(maxlength=200)
  8. action_flag = models.TextField() # This field type is a guess.
  9. change_message = models.TextField()
  10. class Meta:
  11. db_table = 'django_admin_log'

No comments: