X-Git-Url: http://git.ithinksw.org/~kgodey/maayanwich.git/blobdiff_plain/574ee1035dc6ba637a23a0e854b3dcc9e022c755..5d7c130063aa776d8d49bbd2b7f7739ff8331594:/models.py diff --git a/models.py b/models.py index abbf825..3139b47 100644 --- a/models.py +++ b/models.py @@ -1,6 +1,8 @@ from django.db import models from django.contrib.auth.models import User import datetime +from django.core.urlresolvers import reverse +from django.template.defaultfilters import slugify class Ingredient(models.Model): @@ -10,6 +12,7 @@ class Ingredient(models.Model): def __unicode__(self): return self.name + class Sandwich(models.Model): adjective = models.CharField(max_length=200) slug = models.SlugField() @@ -26,3 +29,10 @@ class Sandwich(models.Model): def __unicode__(self): return self.adjective + + def get_absolute_url(self): + return reverse('sandwich_by_slug', kwargs={'slug':self.slug}) + + def save(self, *args, **kwargs): + self.slug = slugify(self.adjective) + super(Sandwich, self).save(*args, **kwargs)