equal
deleted
inserted
replaced
|
1 import random |
|
2 import string |
|
3 import os |
|
4 from django.core.files.storage import FileSystemStorage |
1 from django.db import models |
5 from django.db import models |
2 from django.contrib.auth.models import User |
6 from django.contrib.auth.models import User |
3 import tagging |
7 import tagging |
4 from tagging.fields import TagField |
8 from tagging.fields import TagField |
5 |
9 |
22 ("CM", "Completed")) |
26 ("CM", "Completed")) |
23 |
27 |
24 IMAGES_DIR = "./images" |
28 IMAGES_DIR = "./images" |
25 UPLOADS_DIR = "./uploads" |
29 UPLOADS_DIR = "./uploads" |
26 |
30 |
|
31 class CustomImageStorage(FileSystemStorage): |
|
32 |
|
33 def path(self, name): |
|
34 """ we return images directory path. |
|
35 """ |
|
36 |
|
37 return os.path.join(IMAGES_DIR, name) |
|
38 |
|
39 def get_available_name(self, name): |
|
40 """ here we are going with username as the name of image. |
|
41 """ |
|
42 |
|
43 root, ext = os.path.splitext(name) |
|
44 name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext |
|
45 while self.exists(name): |
|
46 name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext |
|
47 return name |
|
48 |
27 class Profile(models.Model): |
49 class Profile(models.Model): |
28 |
50 |
29 user = models.ForeignKey(User, unique = True) |
51 user = models.ForeignKey(User, unique = True) |
30 dob = models.DateField(verbose_name = u"Date of Birth", help_text = "YYYY-MM-DD") |
52 dob = models.DateField(verbose_name = u"Date of Birth", help_text = "YYYY-MM-DD") |
31 gender = models.CharField(max_length = 1, choices = GENDER_CHOICES) |
53 gender = models.CharField(max_length = 1, choices = GENDER_CHOICES) |
39 homepage = models.URLField(blank = True, verbose_name = u"Homepage/Blog") |
61 homepage = models.URLField(blank = True, verbose_name = u"Homepage/Blog") |
40 street = models.CharField(max_length = 80, blank = True) |
62 street = models.CharField(max_length = 80, blank = True) |
41 city = models.CharField(max_length = 25, blank = True) |
63 city = models.CharField(max_length = 25, blank = True) |
42 country = models.CharField(max_length = 25, blank = True) |
64 country = models.CharField(max_length = 25, blank = True) |
43 nick = models.CharField(max_length = 20, blank = True) |
65 nick = models.CharField(max_length = 20, blank = True) |
44 photo = models.ImageField(upload_to = IMAGES_DIR, blank = True) |
66 photo = models.ImageField(storage = CustomImageStorage(),upload_to = IMAGES_DIR, blank = True) |
45 |
67 |
46 def __unicode__(self): |
68 def __unicode__(self): |
47 return unicode(self.user.username) |
69 return unicode(self.user.username) |
48 |
70 |
49 |
71 |