#coding=utf-8
"""
模型包含内容
栏目:名称,网址,简介
文章:标题,作者,网址,内容
模型关系:
1篇文章只有一个作者
1篇文档可以归属多个栏目
知识点
1.get_absolute_url约定的默认函数,后台会默认调用
2.get_absolute_url也可以通过
django.core.urlresolvers的reverse的名称来进行转换
例如:
reverse(URL_NAME_COLUMN, kwargs={"column_slug_tag":self.slug})
"""
from __future__ import unicode_literals
from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.core.urlresolvers import reverse
from DjangoUeditor.models import UEditorField
from minicms.constant import *
# Create your models here.
#栏目
@python_2_unicode_compatible
class Column(models.Model):
name = models.CharField("栏目名称", max_length=256)
#将slug作为该数据库表的索引
slug = models.CharField("栏目网址", max_length=256, db_index=True)
#简介
intro = models.TextField("简介", default="无简介")
#是否在主页导航栏显示
is_display_in_nav = models.BooleanField("是否在导航栏显示", default=False)
#是否在主页栏目列表显示
is_display_in_list = models.BooleanField("是否在列表显示", default=False)
def __str__(self):
return self.name
#在后台中显示
def __unicode__(self):
return "栏目名称:%s 网址:%s" % (self.name, self.slug)
class Meta:
verbose_name = "栏目"
verbose_name_plural = "栏目_plural"
ordering = ['name']
def get_absolute_url(self):
return reverse(URL_NAME_COLUMN, args=(self.slug,))
#文章
@python_2_unicode_compatible
class Article(models.Model):
column = models.ManyToManyField(Column, verbose_name="归属栏目")
title = models.CharField("标题", max_length=256)
slug = models.CharField("网址",max_length=256,db_index=True)
author = models.CharField("作者",max_length=64)
#content = models.TextField("内容",default="无")
content = UEditorField("内容", height=300, width=1000, default=u"",
blank=True, imagePath="uploads/images/",
toolbars="besttome",
filePath="uploads/files/")
pub_time = models.DateTimeField("发表时间",auto_now_add=True,editable=True)
update_time = models.DateTimeField("更新时间", auto_now=True, null=True)
def __str__(self):
return self.title
def __unicode__(self):
return "标题:%s 网址:%s 作者:%s" % (self.title, self.slug, self.author)
class Meta:
verbose_name="教程演示"
verbose_name_plural = "教程演示_plural"
def get_absolute_url(self):
return reverse(URL_NAME_ARTICLE, args=(self.id,self.slug,))
django开发要点-模型
最新推荐文章于 2024-06-13 10:06:41 发布