X-Git-Url: http://git.ithinksw.org/~kgodey/maayanwich.git/blobdiff_plain/f0692eb63cebfc128d01b6ea46ebe9a5046951f8..HEAD:/models.py?ds=inline diff --git a/models.py b/models.py index 71a8362..37fe7dc 100644 --- a/models.py +++ b/models.py @@ -1,3 +1,38 @@ from django.db import models +from django.contrib.auth.models import User +import datetime +from django.core.urlresolvers import reverse +from slugify import SlugifyUniquely -# Create your models here. + +class Ingredient(models.Model): + name = models.CharField(max_length=100) + slug = models.SlugField(unique=True) + + def __unicode__(self): + return self.name + + +class Sandwich(models.Model): + adjective = models.CharField(max_length=200) + slug = models.SlugField(unique=True) + date_made = models.DateField() + ingredients = models.ManyToManyField(Ingredient) + 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'] + verbose_name_plural = "Sandwiches" + + 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 = SlugifyUniquely(self.adjective, Sandwich) + super(Sandwich, self).save(*args, **kwargs)