X-Git-Url: http://git.ithinksw.org/~kgodey/maayanwich.git/blobdiff_plain/28d54a19591ab7f18b0535e7836a01a48d5dc6c7..d70badd3a28a3b951b32e4cf36562ec3cfd9dd41:/models.py diff --git a/models.py b/models.py index 6c4f4b0..ed6410f 100644 --- a/models.py +++ b/models.py @@ -1,20 +1,15 @@ 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): - name = models.CharField(max_length=100) - slug = models.SlugField() - - def __unicode__(self): - return self.name -class Artist(models.Model): - name = models.CharField(max_length=150) +class Ingredient(models.Model): + name = models.CharField(max_length=100) slug = models.SlugField() - bio = models.TextField() def __unicode__(self): return self.name @@ -26,8 +21,6 @@ class Sandwich(models.Model): date_made = models.DateField() ingredients = models.ManyToManyField(Ingredient) date_added = models.DateTimeField(default=datetime.datetime.now, editable=False) - artist = models.ForeignKey(Artist, related_name='Artist') - patron = models.ForeignKey(Artist, related_name='Patron') picture = models.ImageField(upload_to='sandwiches/') notes = models.TextField() user = models.ForeignKey(User) @@ -38,3 +31,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)