本文整理汇总了Python中profiles.models.Profile.register_extensions方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.register_extensions方法的具体用法?Python Profile.register_extensions怎么用?Python Profile.register_extensions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类profiles.models.Profile
的用法示例。
在下文中一共展示了Profile.register_extensions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: clean_picture
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import register_extensions [as 别名]
from profiles.models import Profile, ProfileAdmin, ProfileForm
Profile.register_extensions(
'dashboard.extensions.manager',
'dashboard.extensions.avatars',
'dashboard.extensions.ssh_key',
'permissions'
)
ProfileAdmin.fieldsets[0][1]['fields'].insert(0, 'username')
def clean_picture(picture, user=None):
"""Return a picture with the name set to that of the given user"""
if user:
ext = picture.name.split('.')[-1]
picture.name = user + '.' + ext
return picture
def clean_avatar(self):
avatar = self.cleaned_data.get('avatar', None)
user = self.cleaned_data.get('username', None)
if avatar and user:
return clean_picture(avatar, user)
ProfileForm.clean_avatar = clean_avatar
def clean_posh_avatar(self):
posh_avatar = self.cleaned_data.get('posh_avatar', None)
user = self.cleaned_data.get('username', None)
if posh_avatar:
return clean_picture(posh_avatar, user)
ProfileForm.clean_posh_avatar = clean_posh_avatar
示例2: Role
# 需要导入模块: from profiles.models import Profile [as 别名]
# 或者: from profiles.models.Profile import register_extensions [as 别名]
})
class Role(models.Model):
name = models.CharField(max_length=255)
def __unicode__(self):
return self.name
class Vote(models.Model):
"""
Users can vote against Items and Comments. Votes can only be positive.
Votes must record the user Role and ID.
"""
TARGET_TYPES = (
('item', 'Item'),
('comment', 'Comment'),
)
target_id = models.IntegerField(null = False, blank = False)
target_type = models.CharField(max_length = 150, null = False,
blank = False, choices=TARGET_TYPES)
created_on = models.DateTimeField(auto_now_add = True)
created_by = models.ForeignKey(User)
class Meta:
ordering = ['-created_on']
unique_together = ("target_id", "target_type")
Profile.register_extensions(InnovationProfile())