Skip to content

Instantly share code, notes, and snippets.

@NekoTashi
Created March 9, 2015 02:20
Show Gist options
  • Save NekoTashi/7cf0e8de9624c872616d to your computer and use it in GitHub Desktop.
Save NekoTashi/7cf0e8de9624c872616d to your computer and use it in GitHub Desktop.
Models
ACTIVITY_LENGUAGE_CHOICE = (
('español', 'Español'),
('english', 'English'),
)
class UserProfile(models.Model):
# relations
user = models.OneToOneField(User)
# attrs
profile_image = models.ImageField(
upload_to=path_and_rename('profile_image/'),
blank=True,
default='/media/profile_image/default_profile_image.jpg'
)
birth_date = models.DateField()
country = models.TextField(max_length=255, blank=True)
city = models.TextField(max_length=255, blank=True)
activation_key = models.CharField(max_length=40, blank=True)
key_expires = models.DateField(default=datetime.date.today())
# functions
@property
def age(self):
today = datetime.date.today()
return today.year - self.birth_date.year - ((today.month, today.day) < (self.birth_date.month, self.birth_date.day))
def __unicode__(self):
return u"%s's userprofile" % (self.user.username)
class Traveler(models.Model):
# relations
userprofile = models.OneToOneField(UserProfile)
# functions
def __unicode__(self):
return u"Traveler %s" % (self.userprofile.user.username)
class Guide(models.Model):
# relations
userprofile = models.OneToOneField(UserProfile)
# functions
def __unicode__(self):
return u"Guide %s" % (self.userprofile.user.username)
class Activity(models.Model):
# relations
guide = models.ForeignKey(Guide)
# attrs
price = models.PositiveSmallIntegerField()
photo = models.ImageField(
upload_to=path_and_rename('photos/'),
default='/media/photos/default_photo.jpg'
)
place = models.CharField(max_length=255)
description = models.TextField(max_length=255)
title = models.CharField(max_length=58)
people = models.PositiveSmallIntegerField(null=True)
activity_length = models.TextField(max_length=255)
activity_language = models.CharField(max_length=128)
slug = AutoSlugField(populate_from='title',
always_update=True
)
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
# short_description = models.TextField(max_length=255, blank=True)
# country = models.TextField(max_length=255, blank=True)
# city = models.TextField(max_length=255, blank=True)
# functions
def __unicode__(self):
return u"Activity: %s in %s" % (self.guide.userprofile.user.username, self.place)
def get_absolute_url(self):
return u'/%s/%s/' % (self.pk, self.slug)
# return reverse('detail_my_activities', args=[self.pk, self.slug])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment