Skip to content

Instantly share code, notes, and snippets.

View mpwoodward's full-sized avatar

Matt Woodward mpwoodward

View GitHub Profile
@mpwoodward
mpwoodward / models.py
Created July 1, 2013 23:31
Registrant and Sponsor models for Old Dog Haven charity walk registration site
class Registrant(models.Model):
first_name = models.CharField(max_length=50, verbose_name='First Name')
last_name = models.CharField(max_length=50, verbose_name='Last Name')
email = models.EmailField(max_length=100, unique=True, verbose_name='Email')
password = models.CharField(max_length=100, verbose_name='Password')
phone = models.CharField(max_length=20, verbose_name='Phone')
address1 = models.CharField(max_length=100, verbose_name='Address')
address2 = models.CharField(max_length=100, blank=True, null=True, verbose_name='Address (cont.)')
city = models.CharField(max_length=100, verbose_name='City')
state = models.CharField(max_length=100, verbose_name='State/Province')
@mpwoodward
mpwoodward / views.py
Created February 21, 2013 04:47
View function using Python sorted() to sort a Django QuerySet based on a transient property on the model class
def user_request_calendar(request):
# there's actually some filtering happening but we'll use all() for brevity
user_requests = UserRequest.objects.all()
user_requests = sorted(user_requests, key=lambda ur: (ur.calendar_date, ur.request_impact))
# rest of view function and return here ...
@mpwoodward
mpwoodward / models.py
Created February 21, 2013 04:36
Python model class with transient property - version 2
class UserRequest(models.Model):
REQUEST_IMPACT = (
('minor', 'Minor'),
('major', 'Major'),
('severe', 'Wake the President'),
)
name = models.CharField(max_length=200)
request_impact = models.CharField(max_length=10, choices=REQUEST_IMPACT)
datetime_supervisor_approved = models.DateTimeField(blank=True, null=True)
@mpwoodward
mpwoodward / models.py
Last active December 14, 2015 00:49
Python model class with various approval dates to illustrate transient properties and sorting
class UserRequest(models.Model):
REQUEST_IMPACT = (
('minor', 'Minor'),
('major', 'Major'),
('severe', 'Wake the President'),
)
name = models.CharField(max_length=200)
request_impact = models.CharField(max_length=10, choices=REQUEST_IMPACT)
datetime_supervisor_approved = models.DateTimeField(blank=True, null=True)