1 from django.db import models
2 from django.contrib.auth.models import User
4 from django.core.urlresolvers import reverse
5 from django.template.defaultfilters import slugify
10 class Ingredient(models.Model):
11 name = models.CharField(max_length=100)
12 slug = models.SlugField()
14 def __unicode__(self):
18 class Sandwich(models.Model):
19 adjective = models.CharField(max_length=200)
20 slug = models.SlugField()
21 date_made = models.DateField()
22 ingredients = models.ManyToManyField(Ingredient)
23 date_added = models.DateTimeField(default=datetime.datetime.now, editable=False)
24 picture = models.ImageField(upload_to='sandwiches/')
25 notes = models.TextField()
26 user = models.ForeignKey(User)
29 ordering = ['date_added']
30 verbose_name_plural = "Sandwiches"
32 def __unicode__(self):
35 def get_absolute_url(self):
36 return reverse('sandwich_by_slug', kwargs={'slug':self.slug})
38 def save(self, *args, **kwargs):
39 self.slug = slugify(self.adjective)
40 super(Sandwich, self).save(*args, **kwargs)