comparison user_photos/models.py @ 696:b2a8fde3173a

Got the image resizing and uploading working. It needs a lot of work though. This commit is just to capture something that works.
author Brian Neal <bgneal@gmail.com>
date Sun, 08 Sep 2013 19:06:54 -0500
parents 2d35e5f97a99
children b6e98717690b
comparison
equal deleted inserted replaced
695:2d35e5f97a99 696:b2a8fde3173a
2 2
3 import datetime 3 import datetime
4 4
5 from django.db import models 5 from django.db import models
6 from django.conf import settings 6 from django.conf import settings
7 from django.core.urlresolvers import reverse
7 8
8 9
9 class Photo(models.Model): 10 class Photo(models.Model):
10 """This model represents data about a user uploaded photo.""" 11 """This model represents data about a user uploaded photo."""
11 user = models.ForeignKey(settings.AUTH_USER_MODEL, 12 user = models.ForeignKey(settings.AUTH_USER_MODEL,
17 def __unicode__(self): 18 def __unicode__(self):
18 return u'Photo by {} on {}'.format(self.user.username, 19 return u'Photo by {} on {}'.format(self.user.username,
19 self.upload_date.strftime('%Y-%m-%d %H:%M:%S')) 20 self.upload_date.strftime('%Y-%m-%d %H:%M:%S'))
20 21
21 def get_absolute_url(self): 22 def get_absolute_url(self):
22 return self.url 23 return reverse('user_photos-detail', kwargs={'pk': self.pk})
23 24
24 def save(self, *args, **kwargs): 25 def save(self, *args, **kwargs):
25 if not self.pk and not self.upload_date: 26 if not self.pk and not self.upload_date:
26 self.upload_date = datetime.datetime.now() 27 self.upload_date = datetime.datetime.now()
27 super(Photo, self).save(*args, **kwargs) 28 super(Photo, self).save(*args, **kwargs)