X-Git-Url: http://git.ithinksw.org/~kgodey/maayanwich.git/blobdiff_plain/7d78aee74972b96c5c3837ccc9e6816e92f5aee6..HEAD:/models.py?ds=sidebyside diff --git a/models.py b/models.py index 4ed80d8..37fe7dc 100644 --- a/models.py +++ b/models.py @@ -1,20 +1,13 @@ from django.db import models from django.contrib.auth.models import User import datetime +from django.core.urlresolvers import reverse +from slugify import SlugifyUniquely 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) - slug = models.SlugField() - bio = models.TextField() + slug = models.SlugField(unique=True) def __unicode__(self): return self.name @@ -22,13 +15,13 @@ class Artist(models.Model): class Sandwich(models.Model): adjective = models.CharField(max_length=200) - slug = models.SlugField() + slug = models.SlugField(unique=True) date_made = models.DateField() - date_added = models.DateTimeField(default=datetime.datetime.now, editable=False) - artist = models.ForeignKey(Artist) ingredients = models.ManyToManyField(Ingredient) - picture = models.ImageField(upload_to='sandwiches/') - notes = models.TextField() + date_added = models.DateTimeField(default=datetime.datetime.now, editable=False) + picture = models.ImageField(upload_to='sandwiches/', blank=True) + notes = models.TextField(blank=True) + user = models.ForeignKey(User) class Meta: ordering = ['date_added'] @@ -36,4 +29,10 @@ class Sandwich(models.Model): def __unicode__(self): return self.adjective - \ No newline at end of file + + def get_absolute_url(self): + return reverse('sandwich_by_slug', kwargs={'slug':self.slug}) + + def save(self, *args, **kwargs): + self.slug = SlugifyUniquely(self.adjective, Sandwich) + super(Sandwich, self).save(*args, **kwargs)