Mercurial > public > sg101
view 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 |
line wrap: on
line source
"""Models for the user_photos application.""" import datetime from django.db import models from django.conf import settings class Photo(models.Model): """This model represents data about a user uploaded photo.""" user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='uploaded_photos') upload_date = models.DateTimeField() url = models.URLField(max_length=200) thumb_url = models.URLField(max_length=200, blank=True) def __unicode__(self): return u'Photo by {} on {}'.format(self.user.username, self.upload_date.strftime('%Y-%m-%d %H:%M:%S')) def get_absolute_url(self): return self.url def save(self, *args, **kwargs): if not self.pk and not self.upload_date: self.upload_date = datetime.datetime.now() super(Photo, self).save(*args, **kwargs)