diff options
-rw-r--r-- | greenbox/settings.py | 23 | ||||
-rw-r--r-- | greenbox/urls.py | 6 | ||||
-rw-r--r-- | greenbox/wsgi.py | 32 | ||||
-rw-r--r-- | recipe/admin.py | 33 | ||||
-rw-r--r-- | recipe/migrations/0002_auto__add_field_unit_grams__add_field_unit_liters.py | 66 | ||||
-rw-r--r-- | recipe/models.py | 66 | ||||
-rw-r--r-- | recipe/urls.py | 9 | ||||
-rw-r--r-- | recipe/views.py | 12 | ||||
-rw-r--r-- | requirements.txt | 6 |
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 @@ | |||
1 | import os | 1 | import os |
2 | 2 | ||
3 | PROJECT_DIR = os.path.dirname(__file__) | 3 | PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) |
4 | PUBLIC_DIR = os.path.join(PROJECT_DIR, 'site_media') | 4 | PUBLIC_DIR = os.path.join(os.path.dirname(__file__), 'site_media') |
5 | 5 | ||
6 | SITE_ID = 1 | 6 | SITE_ID = 1 |
7 | USE_I18N = False | 7 | USE_I18N = False |
8 | DEBUG = True | 8 | TEMPLATE_DEBUG = DEBUG = True |
9 | TEMPLATE_DEBUG = DEBUG | ||
10 | |||
11 | PROJECT_DIR = os.path.abspath(os.path.dirname(__file__)) | ||
12 | |||
13 | ADMINS = ( | ||
14 | ('Mike Crute', 'mcrute@gmail.com'), | ||
15 | ) | ||
16 | 9 | ||
17 | MANAGERS = ADMINS | ||
18 | 10 | ||
19 | DATABASES = { | 11 | DATABASES = { |
20 | 'default': { | 12 | 'default': { |
@@ -27,10 +19,6 @@ TIME_ZONE = 'America/New_York' | |||
27 | LANGUAGE_CODE = 'en-us' | 19 | LANGUAGE_CODE = 'en-us' |
28 | ROOT_URLCONF = 'greenbox.urls' | 20 | ROOT_URLCONF = 'greenbox.urls' |
29 | 21 | ||
30 | |||
31 | MEDIA_ROOT = os.path.join(PUBLIC_DIR, 'media') | ||
32 | MEDIA_URL = '/site_media/media/' | ||
33 | |||
34 | STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static') | 22 | STATIC_ROOT = os.path.join(PUBLIC_DIR, 'static') |
35 | STATIC_URL = '/site_media/static/' | 23 | STATIC_URL = '/site_media/static/' |
36 | 24 | ||
@@ -60,8 +48,3 @@ INSTALLED_APPS = ( | |||
60 | 'south', | 48 | 'south', |
61 | 'recipe', | 49 | 'recipe', |
62 | ) | 50 | ) |
63 | |||
64 | try: | ||
65 | from settings_local import * | ||
66 | except 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 @@ | |||
1 | from django.conf.urls.defaults import patterns, include, url | 1 | from django.conf.urls import patterns, include, url |
2 | from django.contrib import admin; admin.autodiscover() | 2 | |
3 | from django.contrib import admin | ||
4 | admin.autodiscover() | ||
3 | 5 | ||
4 | urlpatterns = patterns('', | 6 | urlpatterns = 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 | """ | ||
2 | WSGI config for imd project. | ||
3 | |||
4 | This module contains the WSGI application used by Django's development server | ||
5 | and any production WSGI deployments. It should expose a module-level variable | ||
6 | named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover | ||
7 | this application via the ``WSGI_APPLICATION`` setting. | ||
8 | |||
9 | Usually you will have the standard Django WSGI application here, but it also | ||
10 | might make sense to replace the whole Django WSGI application with a custom one | ||
11 | that later delegates to the Django one. For example, you could introduce WSGI | ||
12 | middleware here, or combine a Django application with an application of another | ||
13 | framework. | ||
14 | |||
15 | """ | ||
16 | import 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" | ||
22 | os.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. | ||
27 | from django.core.wsgi import get_wsgi_application | ||
28 | application = 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 @@ | |||
1 | from django.contrib import admin | ||
2 | from recipe.models import Unit, Ingredient, Recipe, RecipeIngredient | ||
3 | |||
4 | |||
5 | class UnitAdmin(admin.ModelAdmin): | ||
6 | |||
7 | list_display = ('name', 'abbreviation') | ||
8 | ordering = ('name',) | ||
9 | |||
10 | |||
11 | class IngredientInline(admin.TabularInline): | ||
12 | |||
13 | model = RecipeIngredient | ||
14 | extra = 12 | ||
15 | |||
16 | |||
17 | class RecipeAdmin(admin.ModelAdmin): | ||
18 | |||
19 | list_display = ('title',) | ||
20 | inlines = (IngredientInline,) | ||
21 | search_fields = ('title',) | ||
22 | prepopulated_fields = { "slug": ("title",) } | ||
23 | |||
24 | |||
25 | class IngredientAdmin(admin.ModelAdmin): | ||
26 | |||
27 | list_display = ('name',) | ||
28 | search_fields = ('name',) | ||
29 | |||
30 | |||
31 | admin.site.register(Unit, UnitAdmin) | ||
32 | admin.site.register(Ingredient, IngredientAdmin) | ||
33 | admin.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 -*- | ||
2 | import datetime | ||
3 | from south.db import db | ||
4 | from south.v2 import SchemaMigration | ||
5 | from django.db import models | ||
6 | |||
7 | |||
8 | class 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 @@ | |||
1 | from django.db import models | 1 | from django.db import models |
2 | from django.contrib import admin | ||
3 | from django.db.models import fields | ||
2 | 4 | ||
3 | 5 | ||
4 | class Unit(models.Model): | 6 | class 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 | |||
58 | class UnitAdmin(admin.ModelAdmin): | ||
59 | |||
60 | list_display = ('name', 'abbreviation') | ||
61 | ordering = ('name',) | ||
62 | |||
63 | |||
64 | class IngredientInline(admin.TabularInline): | ||
65 | |||
66 | model = RecipeIngredient | ||
67 | extra = 12 | ||
68 | |||
69 | |||
70 | class RecipeAdmin(admin.ModelAdmin): | ||
71 | |||
72 | list_display = ('title',) | ||
73 | inlines = (IngredientInline,) | ||
74 | search_fields = ('title',) | ||
75 | prepopulated_fields = { "slug": ("title",) } | ||
76 | |||
77 | |||
78 | class IngredientAdmin(admin.ModelAdmin): | ||
79 | |||
80 | list_display = ('name',) | ||
81 | search_fields = ('name',) | ||
82 | |||
83 | |||
84 | try: | ||
85 | admin.site.register(Unit, UnitAdmin) | ||
86 | admin.site.register(Ingredient, IngredientAdmin) | ||
87 | admin.site.register(Recipe, RecipeAdmin) | ||
88 | except 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 @@ | |||
1 | from django.conf.urls.defaults import patterns, url | 1 | from django.conf.urls import patterns, url |
2 | from django.views.generic import DetailView, ListView | ||
3 | |||
4 | from recipe.models import Recipe | ||
2 | 5 | ||
3 | 6 | ||
4 | urlpatterns = patterns('recipe.views', | 7 | urlpatterns = 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 @@ | |||
1 | from models import Recipe | # Views go here | |
2 | from django.views.generic import list_detail | ||
3 | |||
4 | |||
5 | def recipe_list(request): | ||
6 | data = Recipe.objects.all() | ||
7 | return list_detail.object_list(request, queryset=data) | ||
8 | |||
9 | |||
10 | def 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 @@ | |||
1 | Django==1.4 | 1 | Django>=1.6 |
2 | gunicorn==0.17.2 | 2 | South>=0.8 |
3 | South==0.7.6 | 3 | gunicorn>=18.0 |