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):
return self.name
-class Artist(models.Model):
- name = models.CharField(max_length=150)
- slug = models.SlugField()
- bio = models.TextField()
-
- def __unicode__(self):
- return self.name
-
-
class Sandwich(models.Model):
adjective = models.CharField(max_length=200)
slug = models.SlugField()
date_made = models.DateField()
- date_added = models.DateTimeField(default=datetime.datetime.now, editable=False)
- artist = models.ForeignKey(Artist)
- patron = models.CharField(max_length=200)
ingredients = models.ManyToManyField(Ingredient)
+ date_added = models.DateTimeField(default=datetime.datetime.now, editable=False)
picture = models.ImageField(upload_to='sandwiches/')
notes = models.TextField()
user = models.ForeignKey(User)
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)