git.ithinksw.org
/
~kgodey
/
maayanwich.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fixed URLs of one-sandwich views. Fixed adding sandwiches.
[~kgodey/maayanwich.git]
/
models.py
diff --git
a/models.py
b/models.py
index
4ed80d8
..
ed6410f
100644
(file)
--- a/
models.py
+++ b/
models.py
@@
-1,20
+1,15
@@
from django.db import models
from django.contrib.auth.models import User
import datetime
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):
- name = models.CharField(max_length=100)
- slug = models.SlugField()
-
- def __unicode__(self):
- return self.name
-class
Artis
t(models.Model):
- name = models.CharField(max_length=1
5
0)
+class
Ingredien
t(models.Model):
+ name = models.CharField(max_length=1
0
0)
slug = models.SlugField()
slug = models.SlugField()
- bio = models.TextField()
def __unicode__(self):
return self.name
def __unicode__(self):
return self.name
@@
-24,11
+19,11
@@
class Sandwich(models.Model):
adjective = models.CharField(max_length=200)
slug = models.SlugField()
date_made = models.DateField()
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)
ingredients = models.ManyToManyField(Ingredient)
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/')
notes = models.TextField()
+ user = models.ForeignKey(User)
class Meta:
ordering = ['date_added']
class Meta:
ordering = ['date_added']
@@
-36,4
+31,10
@@
class Sandwich(models.Model):
def __unicode__(self):
return self.adjective
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 = slugify(self.adjective)
+ super(Sandwich, self).save(*args, **kwargs)