Total Complexity | 4 |
Total Lines | 23 |
Duplicated Lines | 0 % |
Changes | 6 | ||
Bugs | 1 | Features | 0 |
1 | from django.contrib.auth.models import AbstractUser |
||
6 | class UserProfile(AbstractUser): |
||
7 | |||
8 | twitter = models.CharField(max_length=100, blank=True) |
||
9 | facebook_link = models.URLField(blank=True) |
||
10 | |||
11 | def get_twitter_url(self): |
||
12 | return 'https://twitter.com/{0}'.format(self.twitter) |
||
13 | |||
14 | def save_avatar(self, filename): |
||
15 | extension = filename[filename.rfind('.'):] |
||
16 | new_path = 'user_profile/{}{}-avatar{}'.format( |
||
17 | self.first_name, self.pk, extension) |
||
18 | return new_path |
||
19 | |||
20 | avatar = models.ImageField(upload_to=save_avatar, blank=True) |
||
21 | |||
22 | @property |
||
23 | def get_avatar(self): |
||
24 | return self.avatar.url or '{}/static/img/default.png'.format( |
||
25 | settings.STATIC_URL) |
||
26 | |||
27 | def __str__(self): |
||
28 | return self.username |
||
29 |