Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
be nicer
from django.db import models
from django.contrib.localflavor.us.models import USStateField, PhoneNumberField
def save_area(instance, file_name):
return "photos/%s/%s/%s" % (instance.area.state, instance.area.name, file_name)
# WAT is this? if this is about using nice urls then use url routing instead
def save_problem(instance, file_name):
return "photos/%s/%s/%s/%s" % (instance.problem.parent.state, instance.problem.parent.name, instance.problem.name, file_name)
class Region(models.Model):
lat_lon = ForeignKey('Point')
emergency = ForeignKey('Address')
# other stuff
def get_absolute_url(self):
return "climbs/%s" % (self.slug)
class Boulder(models.Model):
area = ForeignKey('Area') # get the region from the area
lat_lon = ForeignKey('Point')
parking = ForeignKey('Parking')
approach = ForeignKey('Approach')
# other stuff
def get_absolute_url(self):
# urls always composed from parent
return "%s/%s" % (self.area.get_absolute_url(),
self.slug)
class Area(models.Model):
region = ForeignKey('Region')
name = models.CharField(max_length=100)
area_parent = models.ForeignKey("self", null=True, blank=True)
# note that here these are all writen as 1 to many but they can be many to many no problem
address = ForeignKey('Address')
lat_lon = ForeignKey('Point')
approach = ForeignKey('Approach')
parking = ForeignKey('Parking')
emergency = ForeignKey('Address') # you see how that worked?
# what is this anyways? what does it have to do with an area? Just pull from the problems if needed
# height = models.CharField(max_length=20, blank=True)
# tell trish to take this plone BS out. short desc is the first paragraph of description or just do it and don't tell her. She won't notice
# short_description = models.CharField(max_length=120, blank=True)
about = models.TextField(blank=True) # how is this different than description?
description = models.TextField(blank=True)
# move this down to the problem and pull from there
# rock_type = models.CharField(max_length=25, blank=True)
hazard_information = models.CharField(max_length=750, blank=True)
misc_information = models.CharField(max_length=750, blank=True)
pet_friendly = models.BooleanField(default=False)
slug = models.SlugField(max_length=50)
featured = models.BooleanField(default=False)
def __unicode__(self):
return "%s" % self.name
def get_absolute_url(self):
return "%s/%s" % (self.region.get_absolute_url(), self.slug)
class Meta:
ordering = ['name']
class Problem(models.Model):
PROBLEM_QUALITY = (
# Look into having the first value be nums, not strings.
('1', "One Star"),
('2', "Two Star"),
('3', "Three Star"),
('4', "Four Star"),
('5', "Five Star")
)
ANGLE_CHOICES = (
('S', 'Slab'),
('N', '90 Degrees'),
('O', 'Overhang'),
('R', 'Roof')
)
name = models.CharField(max_length=100)
area = models.ForeignKey('Area')
lat_long = models.ForeignKey('Point')
boulder = models.ForeigKey('Boulder')
features = models.MANY TO MANY('Features')
featured = models.BooleanField(default=False)
grade = models.CharField(max_length=6)
quality = models.CharField(max_length=1, choices=PROBLEM_QUALITY, blank=True)
description = models.TextField(blank=True)
height = models.CharField(max_length=20, blank=True)
angle = models.CharField(max_length=1, choices=ANGLE_CHOICES, blank=True)
about = models.TextField(blank=True) # description?
rock_type = models.CharField(max_length=25, blank=True)
start = models.CharField(max_length=100, blank=True)
finish = models.CharField(max_length=100, blank=True)
descent = models.CharField(max_length=100, blank=True)
landing_information = models.CharField(max_length=100, blank=True)
hazard_information = models.CharField(max_length=100, blank=True)
aspect = models.CharField(max_length=50, blank=True)
variations = models.CharField(max_length=100, blank=True)
misc_information = models.CharField(max_length=100, blank=True)
first_ascent = models.CharField(max_length=20, blank=True)
source = models.CharField(max_length=100, blank=True)
slug = models.SlugField(max_length=50, help_text='Used in URL to map to database to this route')
def __unicode__(self):
return "%s: %s, %s" % (self.name, self.parent.area_parent.name, self.parent.state)
def get_absolute_url(self):
return "%s/%s" % (self.boulder.get_absolute_url(), self.slug)
def validate_rating(self):
pass
class Meta:
ordering = ['name']
class ProblemPhoto(models.Model):
PHOTO_CHOICES = (
("O", "Overview"),
("G", "General")
)
photo_type = models.CharField(max_length=1, choices=PHOTO_CHOICES)
problem = models.ForeignKey('Problem')
photo = models.ImageField(upload_to=save_problem)
def __unicode__(self):
return "%s-%s" % (self.problem, self.photo_type)
def get_problem_url(self):
return self.problem.get_absolute_url()
class AreaPhoto(models.Model):
PHOTO_CHOICES = (
("G", "General"),
("A", "Approach"),
)
area = models.ForeignKey('Area')
photo = models.ImageField(upload_to=save_area)
photo_type = models.CharField(max_length=1, choices=PHOTO_CHOICES)
def __unicode__(self):
return "%s-%s" % (self.area, self.photo_type)
def get_area_url(self):
return self.area.get_absolute_url()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.