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.
13 files changed:
------------
Outside of Django_ and the Python_ standard libraries, the only
------------
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_
`python-markdown`_.
__ dt2-docs_
a stand-alone service, you can use the example project written up in
`example`. Set up the project (once)::
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.
$ python example/manage.py syncdb
See the `Django documentation`_ for more details.
.. _Django: https://www.djangoproject.com/
.. _Git: http://git-scm.com/
.. _cookbook: http://physics.drexel.edu/~wking/code/git/gitweb.cgi?p=cookbook.git
.. _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
.. _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
from django.contrib import admin
from django.db import models as django_models
from django.contrib import admin
from django.db import models as django_models
class IngredientInline (admin.TabularInline):
model = models.Ingredient
class IngredientInline (admin.TabularInline):
model = models.Ingredient
+ sortable_field_name = 'position'
class IngredientBlockAdmin (admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['name']}),
class IngredientBlockAdmin (admin.ModelAdmin):
fieldsets = [
(None, {'fields': ['name']}),
class IngredientBlockInline (admin.TabularInline):
model = models.IngredientBlock
fieldsets = [
class IngredientBlockInline (admin.TabularInline):
model = models.IngredientBlock
fieldsets = [
- (None, {'fields': ['name']}),
+ (None, {'fields': ['name', 'position']}),
+ sortable_field_name = 'position'
inlines = [IngredientInline]
inlines = [IngredientInline]
list_display = ['name']
extra = 0
show_edit_link = True # https://code.djangoproject.com/ticket/13163
list_display = ['name']
extra = 0
show_edit_link = True # https://code.djangoproject.com/ticket/13163
class IngredientBlock (Directions):
name = models.CharField(max_length=200)
recipe = models.ForeignKey(Recipe)
class IngredientBlock (Directions):
name = models.CharField(max_length=200)
recipe = models.ForeignKey(Recipe)
+ position = models.PositiveIntegerField()
- ordering = ['recipe', 'name']
+ ordering = ['recipe', 'position']
def __unicode__(self):
return u'{0.name}'.format(self)
def __unicode__(self):
return u'{0.name}'.format(self)
name = models.CharField(max_length=200)
note = models.CharField(max_length=200, null=True, blank=True)
block = models.ForeignKey(IngredientBlock)
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}'
def __unicode__(self):
fmt = '{i.name}'
# Uncomment the next line to enable the admin:
url(r'^admin/', include(admin.site.urls), name='admin'),
# 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'}),
url(r'^favicon\.ico$', 'django.views.generic.simple.redirect_to',
kwargs={'url': settings.STATIC_URL + 'cookbook.ico'}),
# 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/"
# 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 = os.path.join(DATA_DIRECTORY, 'static')
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
# URL prefix for static files.
# Example: "http://media.lawrence.com/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/".
# 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.
# 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
)
# List of finder classes that know how to find static files in
# 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.
# 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'),
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.messages',
'django.contrib.staticfiles',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
'django.contrib.admin',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',