moved media to media folder in app
[~kgodey/maayanwich.git] / models.py
index 3139b47..37fe7dc 100644 (file)
--- a/models.py
+++ b/models.py
@@ -2,12 +2,12 @@ from django.db import models
 from django.contrib.auth.models import User
 import datetime
 from django.core.urlresolvers import reverse
 from django.contrib.auth.models import User
 import datetime
 from django.core.urlresolvers import reverse
-from django.template.defaultfilters import slugify
+from slugify import SlugifyUniquely
 
 
 class Ingredient(models.Model):
        name = models.CharField(max_length=100)
 
 
 class Ingredient(models.Model):
        name = models.CharField(max_length=100)
-       slug = models.SlugField()
+       slug = models.SlugField(unique=True)
        
        def __unicode__(self):
                return self.name
        
        def __unicode__(self):
                return self.name
@@ -15,12 +15,12 @@ class Ingredient(models.Model):
 
 class Sandwich(models.Model):
        adjective = models.CharField(max_length=200)
 
 class Sandwich(models.Model):
        adjective = models.CharField(max_length=200)
-       slug = models.SlugField()
+       slug = models.SlugField(unique=True)
        date_made = models.DateField()
        ingredients = models.ManyToManyField(Ingredient)
        date_added = models.DateTimeField(default=datetime.datetime.now, editable=False)
        date_made = models.DateField()
        ingredients = models.ManyToManyField(Ingredient)
        date_added = models.DateTimeField(default=datetime.datetime.now, editable=False)
-       picture = models.ImageField(upload_to='sandwiches/')
-       notes = models.TextField()
+       picture = models.ImageField(upload_to='sandwiches/', blank=True)
+       notes = models.TextField(blank=True)
        user = models.ForeignKey(User)
        
        class Meta:
        user = models.ForeignKey(User)
        
        class Meta:
@@ -34,5 +34,5 @@ class Sandwich(models.Model):
            return reverse('sandwich_by_slug', kwargs={'slug':self.slug})
        
        def save(self, *args, **kwargs):
            return reverse('sandwich_by_slug', kwargs={'slug':self.slug})
        
        def save(self, *args, **kwargs):
-               self.slug = slugify(self.adjective)
+               self.slug = SlugifyUniquely(self.adjective, Sandwich)
                super(Sandwich, self).save(*args, **kwargs)
                super(Sandwich, self).save(*args, **kwargs)