1 class Group(models.Model): 2 3 name = models.CharField(_('name'), max_length=80, unique=True) 4 permissions = models.ManyToManyField( 5 Permission, 6 verbose_name=_('permissions'), 7 blank=True, 8 ) 9 10 objects = GroupManager() 11 12 class Meta: 13 verbose_name = _('group') 14 verbose_name_plural = _('groups') 15 16 def __str__(self): 17 return self.name 18 19 def natural_key(self): 20 return (self.name,)
1 # -*- coding:utf-8 -*- 2 __author__ = 'webber' 3 """ 4 2016.11.25 5 在看Django的源码django.contrib.auth.models时,发现了一个类内嵌套了一个类,问了下师兄这叫内部类, 6 下面是个例子,简单记录下 7 """ 8 9 class parent: 10 11 def __init__(self): 12 self.name = "parent" 13 14 def getName(self): 15 print self.name 16 17 class child: 18 19 def __init__(self): 20 self.name = "child" 21 22 def getName(self): 23 print self.name 24 25 if __name__ == "__main__": 26 # child = parent.child() 27 # child.getName() 28 29 p = parent() 30 p.getName() 31 32 print "=================" 33 c = p.child() 34 c.getName()