From: W. Trevor King Date: Fri, 5 Aug 2011 16:11:46 +0000 (-0400) Subject: Restructure cookbook directories and use Grappelli for the admin interface. X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=54ef55b5be084b7039fcc40ef4d09f2ff7424aac;p=cookbook.git Restructure cookbook directories and use Grappelli for the admin interface. Moving the static and template directories into the python modules makes it easy for Django to find them using its built-in finders: django.contrib.staticfiles.finders.AppDirectoriesFinder django.template.loaders.app_directories.Loader This means that people using cookbook will not need to shift these files around on their own, or adjust their settings.py file to do more than add 'cookbook' to their INSTALLED_APPS. Grappelli is makes it very easy to add drag-and-drop sorting for Ingredient and IngredientBlock fields, which I also put in in this commit. --- diff --git a/README b/README index e071538..5d723f2 100644 --- a/README +++ b/README @@ -16,7 +16,7 @@ Dependencies ------------ Outside of Django_ and the Python_ standard libraries, the only -required dependencies are `django-taggit`_ (docs__) and +required dependencies are Grappelli_, `django-taggit`_ (docs__) and `python-markdown`_. __ dt2-docs_ @@ -28,6 +28,7 @@ If you don't have a Django project and you just want to run cookbook as a stand-alone service, you can use the example project written up in `example`. Set up the project (once):: + $ python example/manage.py collectstatic $ python example/manage.py syncdb See the `Django documentation`_ for more details. @@ -55,6 +56,7 @@ That's a good place to start if you're new to Django. .. _Django: https://www.djangoproject.com/ .. _Git: http://git-scm.com/ .. _cookbook: http://physics.drexel.edu/~wking/code/git/gitweb.cgi?p=cookbook.git +.. _Grappelli: https://github.com/sehmaschine/django-grappelli .. _django-taggit: https://github.com/alex/django-taggit .. _dt2-docs: http://django-taggit.readthedocs.org/en/latest/ .. _python-markdown: http://pypi.python.org/pypi/Markdown diff --git a/cookbook/admin.py b/cookbook/admin.py index fa29c02..4515bd8 100644 --- a/cookbook/admin.py +++ b/cookbook/admin.py @@ -2,14 +2,14 @@ from django import forms from django.contrib import admin from django.db import models as django_models -import models +from . import models class IngredientInline (admin.TabularInline): model = models.Ingredient + sortable_field_name = 'position' extra = 0 - class IngredientBlockAdmin (admin.ModelAdmin): fieldsets = [ (None, {'fields': ['name']}), @@ -25,10 +25,10 @@ class IngredientBlockAdmin (admin.ModelAdmin): class IngredientBlockInline (admin.TabularInline): model = models.IngredientBlock fieldsets = [ - (None, {'fields': ['name']}), + (None, {'fields': ['name', 'position']}), ] + sortable_field_name = 'position' inlines = [IngredientInline] - list_display = ['name'] extra = 0 show_edit_link = True # https://code.djangoproject.com/ticket/13163 diff --git a/cookbook/models.py b/cookbook/models.py index cfad7b5..f32eb9e 100644 --- a/cookbook/models.py +++ b/cookbook/models.py @@ -129,9 +129,10 @@ class Recipe (Amount, Directions): class IngredientBlock (Directions): name = models.CharField(max_length=200) recipe = models.ForeignKey(Recipe) + position = models.PositiveIntegerField() class Meta: - ordering = ['recipe', 'name'] + ordering = ['recipe', 'position'] def __unicode__(self): return u'{0.name}'.format(self) @@ -142,6 +143,10 @@ class Ingredient (Amount): name = models.CharField(max_length=200) note = models.CharField(max_length=200, null=True, blank=True) block = models.ForeignKey(IngredientBlock) + position = models.PositiveIntegerField() + + class Meta: + ordering = ['block', 'position'] def __unicode__(self): fmt = '{i.name}' diff --git a/example/data/static/cookbook.ico b/cookbook/static/cookbook/cookbook.ico similarity index 100% rename from example/data/static/cookbook.ico rename to cookbook/static/cookbook/cookbook.ico diff --git a/example/data/static/style.css b/cookbook/static/cookbook/style.css similarity index 100% rename from example/data/static/style.css rename to cookbook/static/cookbook/style.css diff --git a/example/data/template/admin/edit_inline/tabular.html b/cookbook/templates/admin/edit_inline/tabular.html similarity index 100% rename from example/data/template/admin/edit_inline/tabular.html rename to cookbook/templates/admin/edit_inline/tabular.html diff --git a/example/data/template/cookbook/base.html b/cookbook/templates/cookbook/base.html similarity index 100% rename from example/data/template/cookbook/base.html rename to cookbook/templates/cookbook/base.html diff --git a/example/data/template/cookbook/recipe.html b/cookbook/templates/cookbook/recipe.html similarity index 100% rename from example/data/template/cookbook/recipe.html rename to cookbook/templates/cookbook/recipe.html diff --git a/example/data/template/cookbook/recipes.html b/cookbook/templates/cookbook/recipes.html similarity index 100% rename from example/data/template/cookbook/recipes.html rename to cookbook/templates/cookbook/recipes.html diff --git a/example/data/template/cookbook/tags.html b/cookbook/templates/cookbook/tags.html similarity index 100% rename from example/data/template/cookbook/tags.html rename to cookbook/templates/cookbook/tags.html diff --git a/cookbook/urls.py b/cookbook/urls.py index 2c5bf64..c242268 100644 --- a/cookbook/urls.py +++ b/cookbook/urls.py @@ -35,6 +35,7 @@ urlpatterns = patterns('', # Uncomment the next line to enable the admin: url(r'^admin/', include(admin.site.urls), name='admin'), + url(r'^grappelli/', include('grappelli.urls'), name='admin'), url(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to', kwargs={'url': settings.STATIC_URL + 'cookbook.ico'}), diff --git a/example/data/static/.gitignore b/example/data/static/.gitignore new file mode 100644 index 0000000..72e8ffc --- /dev/null +++ b/example/data/static/.gitignore @@ -0,0 +1 @@ +* diff --git a/example/settings.py b/example/settings.py index b253e12..49d2f64 100644 --- a/example/settings.py +++ b/example/settings.py @@ -69,7 +69,7 @@ MEDIA_URL = '/media/' # Don't put anything in this directory yourself; store your static files # in apps' "static/" subdirectories and in STATICFILES_DIRS. # Example: "/home/media/media.lawrence.com/static/" -STATIC_ROOT = '' +STATIC_ROOT = os.path.join(DATA_DIRECTORY, 'static') # URL prefix for static files. # Example: "http://media.lawrence.com/static/" @@ -78,15 +78,14 @@ STATIC_URL = '/static/' # URL prefix for admin static files -- CSS, JavaScript and images. # Make sure to use a trailing slash. # Examples: "http://foo.com/static/admin/", "/static/admin/". -ADMIN_MEDIA_PREFIX = '/static/admin/' +#ADMIN_MEDIA_PREFIX = STATIC_URL + 'admin/' +ADMIN_MEDIA_PREFIX = STATIC_URL + 'grappelli/' # Additional locations of static files STATICFILES_DIRS = ( # Put strings here, like "/home/html/static" or "C:/www/django/static". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. - os.path.join(DATA_DIRECTORY, 'media'), - os.path.join(DATA_DIRECTORY, 'static'), ) # List of finder classes that know how to find static files in @@ -121,7 +120,6 @@ TEMPLATE_DIRS = ( # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates". # Always use forward slashes, even on Windows. # Don't forget to use absolute paths, not relative paths. - os.path.join(DATA_DIRECTORY, 'template'), ) INSTALLED_APPS = ( @@ -132,6 +130,7 @@ INSTALLED_APPS = ( 'django.contrib.messages', 'django.contrib.staticfiles', # Uncomment the next line to enable the admin: + 'grappelli', 'django.contrib.admin', # Uncomment the next line to enable admin documentation: # 'django.contrib.admindocs',