taskapp/models.py
changeset 118 5bbb29a07b87
parent 116 cb7f54ed5866
child 119 39ab7c460143
equal deleted inserted replaced
117:58fa1d626d37 118:5bbb29a07b87
    24     ("CM", "Completed"))
    24     ("CM", "Completed"))
    25 
    25 
    26 IMAGES_DIR = "./images"
    26 IMAGES_DIR = "./images"
    27 UPLOADS_DIR = "./uploads"
    27 UPLOADS_DIR = "./uploads"
    28 
    28 
       
    29 def get_key():
       
    30     """ generate a 10 character name with random alphabets and digits.
       
    31     """
       
    32 
       
    33     name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])
       
    34     return name
       
    35 
    29 class CustomImageStorage(FileSystemStorage):
    36 class CustomImageStorage(FileSystemStorage):
    30 
    37 
    31     def path(self, name):
    38     def path(self, name):
    32         """ we return images directory path.
    39         """ we return images directory path.
    33         """
    40         """
    37     def get_available_name(self, name):
    44     def get_available_name(self, name):
    38         """ here we are going with username as the name of image.
    45         """ here we are going with username as the name of image.
    39         """
    46         """
    40     
    47     
    41         root, ext = os.path.splitext(name)
    48         root, ext = os.path.splitext(name)
    42         name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext
    49         file_name = get_key() + ext
    43         while self.exists(name):
    50         while self.exists(file_name):
    44             name = ''.join([ random.choice(string.uppercase+string.digits) for i in range(10)])+ext
    51             file_name = get_key() + ext
    45         return name
    52         return file_name
    46 
    53 
    47 class Profile(models.Model):
    54 class Profile(models.Model):
    48     
    55     
    49     user = models.ForeignKey(User, unique = True)
    56     user = models.ForeignKey(User, unique = True)
    50     dob = models.DateField(verbose_name = u"Date of Birth", help_text = "YYYY-MM-DD")
    57     dob = models.DateField(verbose_name = u"Date of Birth", help_text = "YYYY-MM-DD")