django mate嵌套类

http://my.oschina.net/zhajiang/blog/56814


meta嵌套类

class Person(models.Model):
    first=models.CharField(max_length=100)
    last=models.CharField(max_length=100)
    middle=models.CharField(max_length=100,blank=True)
 
    class Meta:
        #the proper way to oder people,assuming a Last,First M. style of display
        ordering=['last','first','middle']
        #Here we encode the fact that we can't have a person with a 100%
        #identical name. Of course,in real life,we could,but we'll pretend
        #this is an ideal worl
        unique_together=['first','last','middle']
        #Django's default pluralization is simply to add 's' to the end:that
        #doesn't work here.
        verbose_name_plural="people"

Meta 类主要处理模型各种元数据的使用和显示:查询数据表示的排序,数据表的名字等。

django-chinese-docs-16/django-chinese-docs-16-latest/ref/models/options.html




media嵌套类

Assets as a static definition

The easiest way to define assets is as a static definition. Using this method, the declaration is an inner Media class. The properties of the inner class define the requirements.

Here’s a simple example:

from django import forms

class CalendarWidget(forms.TextInput):
    class Media:
        css = {
            'all': ('pretty.css',)
        }
        js = ('animations.js', 'actions.js')

This code defines a CalendarWidget, which will be based on TextInput. Every time the CalendarWidget is used on a form, that form will be directed to include the CSS file pretty.css, and the JavaScript filesanimations.js and actions.js.

This static definition is converted at runtime into a widget property named media. The list of assets for a CalendarWidget instance can be retrieved through this property:

---django-chinese-docs-16/django-chinese-docs-16-latest/topics/forms/media.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值