本文整理汇总了Python中django.db.models.CharField.contribute_to_class方法的典型用法代码示例。如果您正苦于以下问题:Python CharField.contribute_to_class方法的具体用法?Python CharField.contribute_to_class怎么用?Python CharField.contribute_to_class使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.models.CharField
的用法示例。
在下文中一共展示了CharField.contribute_to_class方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contribute_to_class
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import contribute_to_class [as 别名]
def contribute_to_class(self, model, name):
super(MongoUserManager, self).contribute_to_class(model, name)
self.dj_model = self.model
self.model = get_user_document()
self.dj_model.USERNAME_FIELD = self.model.USERNAME_FIELD
username = CharField(_('username'), max_length=30, unique=True)
username.contribute_to_class(self.dj_model, self.dj_model.USERNAME_FIELD)
self.dj_model.REQUIRED_FIELDS = self.model.REQUIRED_FIELDS
for name in self.dj_model.REQUIRED_FIELDS:
field = CharField(_(name), max_length=30)
field.contribute_to_class(self.dj_model, name)
is_staff = BooleanField(_('is_staff'), default=False)
is_staff.contribute_to_class(self.dj_model, 'is_staff')
is_active = BooleanField(_('is_active'), default=False)
is_active.contribute_to_class(self.dj_model, 'is_active')
is_superuser = BooleanField(_('is_superuser'), default=False)
is_superuser.contribute_to_class(self.dj_model, 'is_superuser')
last_login = DateTimeField(_('last_login'), auto_now_add=True)
last_login.contribute_to_class(self.dj_model, 'last_login')
date_joined = DateTimeField(_('date_joined'), auto_now_add=True)
date_joined.contribute_to_class(self.dj_model, 'date_joined')
示例2: contribute_to_class
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import contribute_to_class [as 别名]
def contribute_to_class(self, cls, name):
self.name = name
self.fk_field_name = name + '_fk'
self.ft_field_name = name + '_ft'
setattr(cls, name, self)
fk_field = ForeignKey(self.foreign_model, blank=True, null=True)
fk_field.contribute_to_class(cls, self.fk_field_name)
ft_field = CharField(max_length=255, blank=True)
ft_field.contribute_to_class(cls, self.ft_field_name)
示例3: contribute_to_class
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import contribute_to_class [as 别名]
def contribute_to_class(self, cls, name):
self.name = name
self.fk_field_name = name + '_fk'
self.ft_field_name = name + '_ft'
setattr(cls, name, self)
fk_kwargs = dict(blank=True, null=True)
if self.related_name:
fk_kwargs['related_name'] = self.related_name
fk_field = ForeignKey(self.foreign_model, **fk_kwargs)
fk_field.contribute_to_class(cls, self.fk_field_name)
ft_field = CharField(max_length=255, blank=True, null=True, default='')
ft_field.contribute_to_class(cls, self.ft_field_name)
示例4: contribute_to_class
# 需要导入模块: from django.db.models import CharField [as 别名]
# 或者: from django.db.models.CharField import contribute_to_class [as 别名]
def contribute_to_class(self, model, name):
super(MongoUserManager, self).contribute_to_class(model, name)
self.dj_model = self.model
self.model = get_user_document()
self.dj_model.USERNAME_FIELD = self.model.USERNAME_FIELD
username = CharField(_('username'), max_length=30, unique=True)
username.contribute_to_class(self.dj_model, self.dj_model.USERNAME_FIELD)
self.dj_model.REQUIRED_FIELDS = self.model.REQUIRED_FIELDS
for name in self.dj_model.REQUIRED_FIELDS:
field = CharField(_(name), max_length=30)
field.contribute_to_class(self.dj_model, name)