django-model 一些技巧

使用模块法,简化模型结构


models -- __init__.py, People.py , city.py

__init__.py

from People import *
from city import *

People.py
from django.db import models

class XMan(models.Model):
....


使用模型继承简化模型的设计


class Postable(models.Model):
    created = models.DateTimeField(auto_now_add=True)
    modified = modified.DateTimeField(auto_now=True)
    message = models.TextField(max_length=500)

    class Meta:
        abstract = True


class Post(Postable):
    ...


class Comment(Postable):
...


参考

模型

Loading Disqus comments...
Table of Contents