Mercurial > public > sg101
comparison user_photos/models.py @ 695:2d35e5f97a99
In process work for #50. Started a user_photos application.
Initial commit with model, form, and view. The view doesn't save the photo yet.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 07 Sep 2013 20:50:46 -0500 |
parents | |
children | b2a8fde3173a |
comparison
equal
deleted
inserted
replaced
694:d84aaf239182 | 695:2d35e5f97a99 |
---|---|
1 """Models for the user_photos application.""" | |
2 | |
3 import datetime | |
4 | |
5 from django.db import models | |
6 from django.conf import settings | |
7 | |
8 | |
9 class Photo(models.Model): | |
10 """This model represents data about a user uploaded photo.""" | |
11 user = models.ForeignKey(settings.AUTH_USER_MODEL, | |
12 related_name='uploaded_photos') | |
13 upload_date = models.DateTimeField() | |
14 url = models.URLField(max_length=200) | |
15 thumb_url = models.URLField(max_length=200, blank=True) | |
16 | |
17 def __unicode__(self): | |
18 return u'Photo by {} on {}'.format(self.user.username, | |
19 self.upload_date.strftime('%Y-%m-%d %H:%M:%S')) | |
20 | |
21 def get_absolute_url(self): | |
22 return self.url | |
23 | |
24 def save(self, *args, **kwargs): | |
25 if not self.pk and not self.upload_date: | |
26 self.upload_date = datetime.datetime.now() | |
27 super(Photo, self).save(*args, **kwargs) | |
28 |