CRM项目自定义的知识点

python manage.py shell #自动配置环境 

a = models.CustomerInfo #实例对象可以
a._meta # dir 可以查看字段方法

a._meta.app_label
a._meta.model_name

-->: models.CustomerInfo._meta.fields 获取model所有字段对象

>> models.CustomerInfo._meta.get_field('status') 取一个字段的对象
 

-->: <django.db.models.fields.SmallIntergerField:status>

a = admin_class.model._meta.get_field('name')
a.choices  #取choices属性
if a.choices: #get_xxx_display
data = getattr(obj,"get_%s_display"%name)() #get_status_display 前端方法获取choices的中文val



a). 普通方式 

1
2
3
4
class Foo(object):
  
    def func(self):
        print 'hello alex'

b). 特殊方式

1
2
3
4
5
6
7
def func(self):
    print 'hello wupeiqi'
  
Foo = type('Foo',(object,), {'func': func})
#type第一个参数:类名
#type第二个参数:当前类的基类
#type第三个参数:类的成员


posted on 2018-08-31 18:12  野生大魔王  阅读(183)  评论(0)    收藏  举报