1. class Orderable(with_metaclass(OrderableBase, models.Model)):
  2. """
  3. Abstract model that provides a custom ordering integer field
  4. similar to using Meta's ``order_with_respect_to``, since to
  5. date (Django 1.2) this doesn't work with ``ForeignKey("self")``,
  6. or with Generic Relations. We may also want this feature for
  7. models that aren't ordered with respect to a particular field.
  8. """
  9.  
  10. _order = OrderField(_("Order"), null=True)
  11.  
  12. class Meta:
  13. abstract = True
  14. class OrderableBase(ModelBase):
  15. """
  16. Checks for ``order_with_respect_to`` on the model's inner ``Meta``
  17. class and if found, copies it to a custom attribute and deletes it
  18. since it will cause errors when used with ``ForeignKey("self")``.
  19. Also creates the ``ordering`` attribute on the ``Meta`` class if
  20. not yet provided.
  21. """
  22. class Displayable(Slugged, MetaData, TimeStamped):
  23. """
  24. Abstract model that provides features of a visible page on the
  25. website such as publishing fields. Basis of Mezzanine pages,
  26. blog posts, and Cartridge products.
  27. """
  28.  
  29. status = models.IntegerField(_("Status"),
  30. choices=CONTENT_STATUS_CHOICES, default=CONTENT_STATUS_PUBLISHED,
  31. help_text=_("With Draft chosen, will only be shown for admin users "
  32. "on the site."))
  33. publish_date = models.DateTimeField(_("Published from"),
  34. help_text=_("With Published chosen, won't be shown until this time"),
  35. blank=True, null=True, db_index=True)
  36. expiry_date = models.DateTimeField(_("Expires on"),
  37. help_text=_("With Published chosen, won't be shown after this time"),
  38. blank=True, null=True)
  39. short_url = models.URLField(blank=True, null=True)
  40. in_sitemap = models.BooleanField(_("Show in sitemap"), default=True)
  41.  
  42. objects = DisplayableManager()
  43. search_fields = {"keywords": 10, "title": 5}
  44.  
  45. class Meta:
  46. abstract = True
  47. class Slugged(SiteRelated):
  48. """
  49. Abstract model that handles auto-generating slugs. Each slugged
  50. object is also affiliated with a specific site object.
  51. """
  52.  
  53. title = models.CharField(_("Title"), max_length=500)
  54. slug = models.CharField(_("URL"), max_length=2000, blank=True, null=True,
  55. help_text=_("Leave blank to have the URL auto-generated from "
  56. "the title."))
  57.  
  58. class Meta:
  59. abstract = True
  60.  
  61. class SiteRelated(models.Model):
  62. """
  63. Abstract model for all things site-related. Adds a foreignkey to
  64. Django's ``Site`` model, and filters by site with all querysets.
  65. See ``mezzanine.utils.sites.current_site_id`` for implementation
  66. details.
  67. """
  68.  
  69. objects = CurrentSiteManager()
  70.  
  71. class Meta:
  72. abstract = True
  73.  
  74. site = models.ForeignKey("sites.Site", editable=False)
  75.  
  76. class MetaData(models.Model):
  77. """
  78. Abstract model that provides meta data for content.
  79. """
  80.  
  81. _meta_title = models.CharField(_("Title"), null=True, blank=True,
  82. max_length=500,
  83. help_text=_("Optional title to be used in the HTML title tag. "
  84. "If left blank, the main title field will be used."))
  85. description = models.TextField(_("Description"), blank=True)
  86. gen_description = models.BooleanField(_("Generate description"),
  87. help_text=_("If checked, the description will be automatically "
  88. "generated from content. Uncheck if you want to manually "
  89. "set a custom description."), default=True)
  90. keywords = KeywordsField(verbose_name=_("Keywords"))
  91. class TimeStamped(models.Model):
  92. """
  93. Provides created and updated timestamps on models.
  94. """
  95.  
  96. class Meta:
  97. abstract = True
  98.  
  99. created = models.DateTimeField(null=True, editable=False)
  100. updated = models.DateTimeField(null=True, editable=False)
  101.  
  1. lass Page(BasePage):
  2. """
  3. A page in the page tree. This is the base class that custom content types
  4. need to subclass.
  5. """
  6.  
  7. parent = models.ForeignKey("Page", blank=True, null=True,
  8. related_name="children")
  9. in_menus = MenusField(_("Show in menus"), blank=True, null=True)
  10. titles = models.CharField(editable=False, max_length=1000, null=True)
  11. content_model = models.CharField(editable=False, max_length=50, null=True)
  12. login_required = models.BooleanField(_("Login required"), default=False,
  13. help_text=_("If checked, only logged in users can view this page"))
  14.  
  15. class Meta:
  16. verbose_name = _("Page")
  17. verbose_name_plural = _("Pages")
  18. ordering = ("titles",)
  19. order_with_respect_to = "parent"

model的Meta abstract为True的,不会生成数据库表。

CREATE TABLE "pages_page" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "keywords_string" varchar(500) NOT NULL, "title" varchar(500) NOT NULL, "slug" varchar(2000) NULL, "_meta_title" varchar(500) NULL, "description" text NOT NULL, "gen_description" bool NOT NULL, "created" datetime NULL, "updated" datetime NULL, "status" integer NOT NULL, "expiry_date" datetime NULL, "short_url" varchar(200) NULL, "in_sitemap" bool NOT NULL, "_order" integer NULL, "in_menus" varchar(100) NULL, "titles" varchar(1000) NULL, "content_model" varchar(50) NULL, "login_required" bool NOT NULL, "parent_id" integer NULL REFERENCES "pages_page" ("id"), "site_id" integer NOT NULL REFERENCES "django_site" ("id"), "publish_date" datetime NULL);

CREATE INDEX "pages_page_9365d6e7" ON "pages_page" ("site_id");

CREATE INDEX "pages_page_6be37982" ON "pages_page" ("parent_id");

CREATE INDEX "pages_page_76776489" ON "pages_page" ("publish_date");

mezzanine的page表的更多相关文章

  1. django之ModelBase类及mezzanine的page link类

    class ModelBase(type): """ Metaclass for all models. """ def __new__(c ...

  2. mysql 数据库封装类:返回索引、关联、字符串数组;分页查询封装类 :$page=new Page(表的总条数,每页的条数);$sql = "".$page->limit; echo $page->fpage();

    <?php class czy { public $host="localhost"; //地址 public $uid="root"; //用户名 pu ...

  3. [MySQL Reference Manual]14 InnoDB存储引擎

    14 InnoDB存储引擎 14 InnoDB存储引擎 14.1 InnoDB说明 14.1.1 InnoDB作为默认存储引擎 14.1.1.1 存储引擎的趋势 14.1.1.2 InnoDB变成默认 ...

  4. Selenium Web 自动化 - 项目实战(三)

    Selenium Web 自动化 - 项目实战(三) 2016-08-10 目录 1 关键字驱动概述2 框架更改总览3 框架更改详解  3.1 解析新增页面目录  3.2 解析新增测试用例目录  3. ...

  5. 7. redis优化

    一. redis使用上的优化 精简键名和键值 键名:尽量精简,但是也不能单纯为了节约空间而使用不易理解的键名. 键值:对于键值的数量固定的话可以使用0和1这样的数字来表示,(例如:male/femal ...

  6. mysql ERROR 1064 (42000): Erreur de syntaxe près de 'order)

    mysql> INSERT INTO page (author_username, page_title, addtime, cat_id, page_content,author_uid,it ...

  7. Flexigrid的API

    基本设定 width  table的长度(default:auto) height  table的宽度(default:200) striped   表格的线的表示(default:true) nov ...

  8. Redis学习——Linux环境下Redis的安装(一)

    一.关于Redis Redis最为一款开源的key-value存储系统,自推出到现在一直受到编程人员的喜爱.它支持存储多种value类型,String .List .Set .Zset .Hash.这 ...

  9. [No0000137]字符编码详解

    摘要 本文主要介绍了字符编码的基础知识,以及常见的字符编码类型,比如ASCII,Unicode,UTF-8,ISO 8859等,以及各种编码之间的关系,同时专门解释了中文字符相关的编码标准,包括GB2 ...

随机推荐

  1. 黄聪:如何高效率存储微信中的 access_token

    众所周知,在微信开发中,获取access_token 的接口每天的调用次数是有限制的,2000次应该是. 不过其实这些完全够用了,除非你不小心写了个循环,在1秒中内用完了. 每个access_toke ...

  2. yarn和npm命令对比

  3. STL基础--String

    String 构造 string s1("Hello"); string s2("Hello", 3); //s2: Hel string s3(s1, 2); ...

  4. C++进阶--静态初始化的惨败

    /* Initialization Fiasco 一个会使程序崩溃的细微的问题 */ // 不同文件的编译顺序是不确定的 // 如果一个文件依赖另一个文件的对象先初始化,可能出现问题 // 解决方法: ...

  5. Spring MVC + Mybatis项目搭建

    1.参考<Java Spring MVC项目搭建(一)——Spring MVC框架集成>配置spring mvc需要的jar包及eclipse配置(主要是针对servlet-api.jar ...

  6. [UE4]子弹穿透多个机器人

    一.将机器人的碰撞类型改成“OverLap” 二.使用“MultiLineTraceByChannel”这个是可以穿透检测,可以检测到多个物体(前提是被检测物体的碰撞类型是“OverLap”).“Li ...

  7. Java的Start和Runnable方法的区别

    两种方法的区别 1) start:用法:start方法来启动线程,真正实现了多线程运行,这时无需等待run方法体代码执行完毕而直接继续执行下面的代码.通过调用Thread类的start()方法来启动一 ...

  8. springmvc+mybatis+redis的session共享+maven管理

    负载均衡搭建:http://www.cnblogs.com/guoyansi19900907/p/8717746.html redis安装:http://www.cnblogs.com/guoyans ...

  9. 第11章 拾遗5:IPv6和IPv4共存技术(3)_NAT-PT技术【全书完】

    6.4 NAT-PT (1)NAT-PT和NAT的差别 ①NAT-PT(附带协议转换的网络地址转换)技术秉承NAT技术的思想,但在原理方面大有不同. ②NAT-PT和NAT本质的区别在于应用场合的不同 ...

  10. 第10章 网络安全(3)_安全套接字层SSL

    4. 安全套接字层 4.1 安全套接字层(SSL)和传输层安全(TLS) (1)SSL/TLS提供的安全服务 ①SSL服务器鉴别,允许用户证实服务器的身份.支持SSL的客户端通过验证来自服务器的证书, ...