class Orderable(with_metaclass(OrderableBase, models.Model)): """ Abstract model that provides a custom ordering integer field similar to using Meta's ``order_with_respect_to``, since to date (Django 1.2) this doesn't work with ``ForeignKey("self")``, or with Generic Relations. We may also want this feature for models that aren't ordered with respect to a particular field. """ _order = OrderField(_("Order"), null=True) class Meta: abstract = True class OrderableBase(ModelBase): """ Checks for ``order_with_respect_to`` on the model's inner ``Meta`` class and if found, copies it to a custom attribute and deletes it since it will cause errors when used with ``ForeignKey("self")``. Also creates the ``ordering`` attribute on the ``Meta`` class if not yet provided. """ class Displayable(Slugged, MetaData, TimeStamped): """ Abstract model that provides features of a visible page on the website such as publishing fields. Basis of Mezzanine pages, blog posts, and Cartridge products. """ status = models.IntegerField(_("Status"), choices=CONTENT_STATUS_CHOICES, default=CONTENT_STATUS_PUBLISHED, help_text=_("With Draft chosen, will only be shown for admin users " "on the site.")) publish_date = models.DateTimeField(_("Published from"), help_text=_("With Published chosen, won't be shown until this time"), blank=True, null=True, db_index=True) expiry_date = models.DateTimeField(_("Expires on"), help_text=_("With Published chosen, won't be shown after this time"), blank=True, null=True) short_url = models.URLField(blank=True, null=True) in_sitemap = models.BooleanField(_("Show in sitemap"), default=True) objects = DisplayableManager() search_fields = {"keywords": 10, "title": 5} class Meta: abstract = True class Slugged(SiteRelated): """ Abstract model that handles auto-generating slugs. Each slugged object is also affiliated with a specific site object. """ title = models.CharField(_("Title"), max_length=500) slug = models.CharField(_("URL"), max_length=2000, blank=True, null=True, help_text=_("Leave blank to have the URL auto-generated from " "the title.")) class Meta: abstract = True class SiteRelated(models.Model): """ Abstract model for all things site-related. Adds a foreignkey to Django's ``Site`` model, and filters by site with all querysets. See ``mezzanine.utils.sites.current_site_id`` for implementation details. """ objects = CurrentSiteManager() class Meta: abstract = True site = models.ForeignKey("sites.Site", editable=False) class MetaData(models.Model): """ Abstract model that provides meta data for content. """ _meta_title = models.CharField(_("Title"), null=True, blank=True, max_length=500, help_text=_("Optional title to be used in the HTML title tag. " "If left blank, the main title field will be used.")) description = models.TextField(_("Description"), blank=True) gen_description = models.BooleanField(_("Generate description"), help_text=_("If checked, the description will be automatically " "generated from content. Uncheck if you want to manually " "set a custom description."), default=True) keywords = KeywordsField(verbose_name=_("Keywords")) class TimeStamped(models.Model): """ Provides created and updated timestamps on models. """ class Meta: abstract = True created = models.DateTimeField(null=True, editable=False) updated = models.DateTimeField(null=True, editable=False)
lass Page(BasePage): """ A page in the page tree. This is the base class that custom content types need to subclass. """ parent = models.ForeignKey("Page", blank=True, null=True, related_name="children") in_menus = MenusField(_("Show in menus"), blank=True, null=True) titles = models.CharField(editable=False, max_length=1000, null=True) content_model = models.CharField(editable=False, max_length=50, null=True) login_required = models.BooleanField(_("Login required"), default=False, help_text=_("If checked, only logged in users can view this page")) class Meta: verbose_name = _("Page") verbose_name_plural = _("Pages") ordering = ("titles",) 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");

浙公网安备 33010602011771号