summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--greenbox/settings.py23
-rw-r--r--greenbox/urls.py6
-rw-r--r--greenbox/wsgi.py32
-rw-r--r--recipe/admin.py33
-rw-r--r--recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py66
-rw-r--r--recipe/models.py66
-rw-r--r--recipe/urls.py9
-rw-r--r--recipe/views.py12
-rw-r--r--requirements.txt6
9 files changed, 97 insertions, 156 deletions
diff --git a/greenbox/settings.py b/greenbox/settings.py
index a0096ed..939f396 100644
--- a/greenbox/settings.py
+++ b/greenbox/settings.py
@@ -1,20 +1,12 @@
1import os 1import os
2 2
3PROJECT_DIR = os.path.dirname(__file__) 3PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
4PUBLIC_DIR = os.path.join(PROJECT_DIR, 'site_media') 4PUBLIC_DIR = os.path.join(os.path.dirname(__file__), 'site_media')
5 5
6SITE_ID = 1 6SITE_ID = 1
7USE_I18N = False 7USE_I18N = False
8DEBUG = True 8TEMPLATE_DEBUG = DEBUG = True
9TEMPLATE_DEBUG = DEBUG
10
11PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
12
13ADMINS = (
14 ('Mike Crute', 'mcrute@gmail.com'),
15)
16 9
17MANAGERS = ADMINS
18 10
19DATABASES = { 11DATABASES = {
20 'default': { 12 'default': {
@@ -27,10 +19,6 @@ TIME_ZONE = 'America/New_York'
27LANGUAGE_CODE = 'en-us' 19LANGUAGE_CODE = 'en-us'
28ROOT_URLCONF = 'greenbox.urls' 20ROOT_URLCONF = 'greenbox.urls'
29 21
30
31MEDIA_ROOT = os.path.join(PUBLIC_DIR, 'media')
32MEDIA_URL = '/site_media/media/'
33
34STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static') 22STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static')
35STATIC_URL = '/site_media/static/' 23STATIC_URL = '/site_media/static/'
36 24
@@ -60,8 +48,3 @@ INSTALLED_APPS = (
60 'south', 48 'south',
61 'recipe', 49 'recipe',
62) 50)
63
64try:
65 from settings_local import *
66except ImportError:
67 pass
diff --git a/greenbox/urls.py b/greenbox/urls.py
index fb38894..1e6b755 100644
--- a/greenbox/urls.py
+++ b/greenbox/urls.py
@@ -1,5 +1,7 @@
1from django.conf.urls.defaults import patterns, include, url 1from django.conf.urls import patterns, include, url
2from django.contrib import admin; admin.autodiscover() 2
3from django.contrib import admin
4admin.autodiscover()
3 5
4urlpatterns = patterns('', 6urlpatterns = patterns('',
5 url(r'^admin/', include(admin.site.urls)), 7 url(r'^admin/', include(admin.site.urls)),
diff --git a/greenbox/wsgi.py b/greenbox/wsgi.py
new file mode 100644
index 0000000..0e2d030
--- /dev/null
+++ b/greenbox/wsgi.py
@@ -0,0 +1,32 @@
1"""
2WSGI config for imd project.
3
4This module contains the WSGI application used by Django's development server
5and any production WSGI deployments. It should expose a module-level variable
6named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
7this application via the ``WSGI_APPLICATION`` setting.
8
9Usually you will have the standard Django WSGI application here, but it also
10might make sense to replace the whole Django WSGI application with a custom one
11that later delegates to the Django one. For example, you could introduce WSGI
12middleware here, or combine a Django application with an application of another
13framework.
14
15"""
16import os
17
18# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
19# if running multiple sites in the same mod_wsgi process. To fix this, use
20# mod_wsgi daemon mode with each site in its own daemon process, or use
21# os.environ["DJANGO_SETTINGS_MODULE"] = "imd.settings"
22os.environ.setdefault("DJANGO_SETTINGS_MODULE", "greenbox.settings")
23
24# This application object is used by any WSGI server configured to use this
25# file. This includes Django's development server, if the WSGI_APPLICATION
26# setting points here.
27from django.core.wsgi import get_wsgi_application
28application = get_wsgi_application()
29
30# Apply WSGI middleware here.
31# from helloworld.wsgi import HelloWorldApplication
32# application = HelloWorldApplication(application)
diff --git a/recipe/admin.py b/recipe/admin.py
deleted file mode 100644
index 12bf0fa..0000000
--- a/recipe/admin.py
+++ /dev/null
@@ -1,33 +0,0 @@
1from django.contrib import admin
2from recipe.models import Unit, Ingredient, Recipe, RecipeIngredient
3
4
5class UnitAdmin(admin.ModelAdmin):
6
7 list_display = ('name', 'abbreviation')
8 ordering = ('name',)
9
10
11class IngredientInline(admin.TabularInline):
12
13 model = RecipeIngredient
14 extra = 12
15
16
17class RecipeAdmin(admin.ModelAdmin):
18
19 list_display = ('title',)
20 inlines = (IngredientInline,)
21 search_fields = ('title',)
22 prepopulated_fields = { "slug": ("title",) }
23
24
25class IngredientAdmin(admin.ModelAdmin):
26
27 list_display = ('name',)
28 search_fields = ('name',)
29
30
31admin.site.register(Unit, UnitAdmin)
32admin.site.register(Ingredient, IngredientAdmin)
33admin.site.register(Recipe, RecipeAdmin)
diff --git a/recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py b/recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py
deleted file mode 100644
index 215c81c..0000000
--- a/recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py
+++ /dev/null
@@ -1,66 +0,0 @@
1# -*- coding: utf-8 -*-
2import datetime
3from south.db import db
4from south.v2 import SchemaMigration
5from django.db import models
6
7
8class Migration(SchemaMigration):
9
10 def forwards(self, orm):
11 # Adding field 'Unit.grams'
12 db.add_column('recipe_unit', 'grams',
13 self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=10, decimal_places=10, blank=True),
14 keep_default=False)
15
16 # Adding field 'Unit.liters'
17 db.add_column('recipe_unit', 'liters',
18 self.gf('django.db.models.fields.DecimalField')(null=True, max_digits=10, decimal_places=10, blank=True),
19 keep_default=False)
20
21
22 def backwards(self, orm):
23 # Deleting field 'Unit.grams'
24 db.delete_column('recipe_unit', 'grams')
25
26 # Deleting field 'Unit.liters'
27 db.delete_column('recipe_unit', 'liters')
28
29
30 models = {
31 'recipe.ingredient': {
32 'Meta': {'ordering': "('name',)", 'object_name': 'Ingredient'},
33 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
34 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '100'})
35 },
36 'recipe.recipe': {
37 'Meta': {'ordering': "('title',)", 'object_name': 'Recipe'},
38 'cook_time': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
39 'description': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
40 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
41 'instructions': ('django.db.models.fields.TextField', [], {}),
42 'oven_temp': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
43 'prep_time': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
44 'servings': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}),
45 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '150'}),
46 'title': ('django.db.models.fields.CharField', [], {'max_length': '100'})
47 },
48 'recipe.recipeingredient': {
49 'Meta': {'object_name': 'RecipeIngredient'},
50 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
51 'ingredient': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['recipe.Ingredient']"}),
52 'quantity': ('django.db.models.fields.FloatField', [], {}),
53 'recipe': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['recipe.Recipe']"}),
54 'units': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['recipe.Unit']"})
55 },
56 'recipe.unit': {
57 'Meta': {'ordering': "('name',)", 'object_name': 'Unit'},
58 'abbreviation': ('django.db.models.fields.CharField', [], {'max_length': '10', 'null': 'True', 'blank': 'True'}),
59 'grams': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '10', 'blank': 'True'}),
60 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
61 'liters': ('django.db.models.fields.DecimalField', [], {'null': 'True', 'max_digits': '10', 'decimal_places': '10', 'blank': 'True'}),
62 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
63 }
64 }
65
66 complete_apps = ['recipe'] \ No newline at end of file
diff --git a/recipe/models.py b/recipe/models.py
index 1db7f42..548536e 100644
--- a/recipe/models.py
+++ b/recipe/models.py
@@ -1,4 +1,6 @@
1from django.db import models 1from django.db import models
2from django.contrib import admin
3from django.db.models import fields
2 4
3 5
4class Unit(models.Model): 6class Unit(models.Model):
@@ -6,14 +8,8 @@ class Unit(models.Model):
6 class Meta: 8 class Meta:
7 ordering = ('name',) 9 ordering = ('name',)
8 10
9 name = models.CharField(max_length=100) 11 name = fields.CharField(max_length=100)
10 abbreviation = models.CharField(max_length=10, blank=True, null=True) 12 abbreviation = fields.CharField(max_length=10, blank=True, null=True)
11 grams = models.DecimalField(max_digits=10, decimal_places=10,
12 blank=True, null=True,
13 help_text="Conversion from this unit to grams (dry measure)")
14 liters = models.DecimalField(max_digits=10, decimal_places=10,
15 blank=True, null=True,
16 help_text="Conversion from this unit to liters (liquid measure)")
17 13
18 def __unicode__(self): 14 def __unicode__(self):
19 return "{0} ({1})".format(self.name, self.abbreviation) 15 return "{0} ({1})".format(self.name, self.abbreviation)
@@ -24,14 +20,14 @@ class Recipe(models.Model):
24 class Meta: 20 class Meta:
25 ordering = ('title',) 21 ordering = ('title',)
26 22
27 title = models.CharField(max_length=100) 23 title = fields.CharField(max_length=100)
28 slug = models.SlugField(max_length=150) 24 slug = fields.SlugField(max_length=150)
29 description = models.TextField(blank=True, null=True) 25 description = fields.TextField(blank=True, null=True)
30 servings = models.IntegerField(blank=True, null=True) 26 servings = fields.IntegerField(blank=True, null=True)
31 instructions = models.TextField() 27 instructions = fields.TextField()
32 oven_temp = models.IntegerField(blank=True, null=True) 28 oven_temp = fields.IntegerField(blank=True, null=True)
33 cook_time = models.IntegerField(blank=True, null=True, help_text="In minutes") 29 cook_time = fields.IntegerField(blank=True, null=True, help_text="In minutes")
34 prep_time = models.IntegerField(blank=True, null=True, help_text="In minutes") 30 prep_time = fields.IntegerField(blank=True, null=True, help_text="In minutes")
35 31
36 def __unicode__(self): 32 def __unicode__(self):
37 return self.title 33 return self.title
@@ -42,7 +38,7 @@ class Ingredient(models.Model):
42 class Meta: 38 class Meta:
43 ordering = ('name',) 39 ordering = ('name',)
44 40
45 name = models.CharField(max_length=100, unique=True) 41 name = fields.CharField(max_length=100, unique=True)
46 42
47 def __unicode__(self): 43 def __unicode__(self):
48 return self.name 44 return self.name
@@ -52,8 +48,42 @@ class RecipeIngredient(models.Model):
52 48
53 ingredient = models.ForeignKey(Ingredient) 49 ingredient = models.ForeignKey(Ingredient)
54 units = models.ForeignKey(Unit) 50 units = models.ForeignKey(Unit)
55 quantity = models.FloatField() 51 quantity = fields.FloatField()
56 recipe = models.ForeignKey(Recipe) 52 recipe = models.ForeignKey(Recipe)
57 53
58 def __unicode__(self): 54 def __unicode__(self):
59 return "{0} in {1}".format(self.ingredient.name, self.recipe.title) 55 return "{0} in {1}".format(self.ingredient.name, self.recipe.title)
56
57
58class UnitAdmin(admin.ModelAdmin):
59
60 list_display = ('name', 'abbreviation')
61 ordering = ('name',)
62
63
64class IngredientInline(admin.TabularInline):
65
66 model = RecipeIngredient
67 extra = 12
68
69
70class RecipeAdmin(admin.ModelAdmin):
71
72 list_display = ('title',)
73 inlines = (IngredientInline,)
74 search_fields = ('title',)
75 prepopulated_fields = { "slug": ("title",) }
76
77
78class IngredientAdmin(admin.ModelAdmin):
79
80 list_display = ('name',)
81 search_fields = ('name',)
82
83
84try:
85 admin.site.register(Unit, UnitAdmin)
86 admin.site.register(Ingredient, IngredientAdmin)
87 admin.site.register(Recipe, RecipeAdmin)
88except admin.sites.AlreadyRegistered:
89 pass
diff --git a/recipe/urls.py b/recipe/urls.py
index 4c937a0..00bc44a 100644
--- a/recipe/urls.py
+++ b/recipe/urls.py
@@ -1,7 +1,10 @@
1from django.conf.urls.defaults import patterns, url 1from django.conf.urls import patterns, url
2from django.views.generic import DetailView, ListView
3
4from recipe.models import Recipe
2 5
3 6
4urlpatterns = patterns('recipe.views', 7urlpatterns = patterns('recipe.views',
5 url(r'^(?P<slug>[^/]+)', 'recipe_details'), 8 url(r'^(?P<slug>[^/]+)', DetailView.as_view(model=Recipe)),
6 url(r'^$', 'recipe_list'), 9 url(r'^$', ListView.as_view(model=Recipe)),
7) 10)
diff --git a/recipe/views.py b/recipe/views.py
index 3efdb9e..7e324b4 100644
--- a/recipe/views.py
+++ b/recipe/views.py
@@ -1,11 +1 @@
1from models import Recipe # Views go here
2from django.views.generic import list_detail
3
4
5def recipe_list(request):
6 data = Recipe.objects.all()
7 return list_detail.object_list(request, queryset=data)
8
9
10def recipe_details(request, slug):
11 return list_detail.object_detail(request, queryset=Recipe.objects.all(), slug=slug)
diff --git a/requirements.txt b/requirements.txt
index 9ae3a99..b632dff 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,3 +1,3 @@
1Django==1.4 1Django>=1.6
2gunicorn==0.17.2 2South>=0.8
3South==0.7.6 3gunicorn>=18.0