您的位置:首页 > 编程语言 > Go语言

Django模型的属性(Meta)

2012-12-31 22:12 302 查看
http://docs.djangoproject.com/en/dev/topics/db/models/#meta-options

http://docs.djangoproject.com/en/dev/ref/models/options/

Meta
class 模型(models.Model):
  字段=...
  class Meta:
    选项...    #在类的内部类Meta中设置选项

abstract = True    #设置类模型是否成为抽象类,在子类模型中就可以带父类的字段

class 子类(抽象模型):
  ...
  class Meta(抽象模型.Meta):
    ...

db_table='指定数据库的表名称'

db_tablespace=''    #表空间?

get_latest_by='pub_date'    #设置模型里DateField 或 DateTimeField的名称
<<< Entry.objects.latest('pub_date')    #调用

managed =

class Answer(models.Model):
  question = models.ForeignKey(Question)

  class Meta:
    order_with_respect_to='question'    #关联,问题对应多个答案,设置答案的顺序

ordering=['字段一','字段二']    #本模型排序,字段名前引号内加-号,表示反向排序

permissions=(("can_deliver_pizzas","Can deliver pizzas"),)    #权限,元组对

proxy=True    #

unique_together = [("department", "extension")]    #几个字段的组合值必须是唯一的

verbose_name = "order"    #模型的友好名字

verbose_name_plural="名字加s"    #如没有值,会用verbose_name的值后加s
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: