Skip to content

Commit 347e3ef

Browse files
committed
Merge pull request #20 from g3rd/django_1.7_support
Django 1.7 support
2 parents ce9faeb + 657ee98 commit 347e3ef

File tree

16 files changed

+316
-3
lines changed

16 files changed

+316
-3
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
build/
1212
dist/
1313
docs/_build/
14+
*.sqlite3

example/example/__init__.py

Whitespace-only changes.

example/example/settings.py

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
"""
2+
Django settings for example project.
3+
4+
For more information on this file, see
5+
https://docs.djangoproject.com/en/1.7/topics/settings/
6+
7+
For the full list of settings and their values, see
8+
https://docs.djangoproject.com/en/1.7/ref/settings/
9+
"""
10+
11+
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
12+
import os
13+
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
14+
15+
16+
# Quick-start development settings - unsuitable for production
17+
# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/
18+
19+
# SECURITY WARNING: keep the secret key used in production secret!
20+
SECRET_KEY = 'qr28ym=4y!9e!^owr&k$++8*v$1mvp=u!p7f)+hi2zb7&n6+39'
21+
22+
# SECURITY WARNING: don't run with debug turned on in production!
23+
DEBUG = True
24+
25+
TEMPLATE_DEBUG = True
26+
27+
ALLOWED_HOSTS = []
28+
29+
30+
# Application definition
31+
32+
INSTALLED_APPS = (
33+
'django.contrib.admin',
34+
'django.contrib.auth',
35+
'django.contrib.contenttypes',
36+
'django.contrib.sessions',
37+
'django.contrib.messages',
38+
'django.contrib.staticfiles',
39+
40+
# Translators: Install django-polymorphic-tree and dependent apps
41+
'polymorphic_tree',
42+
'polymorphic',
43+
'mptt',
44+
45+
# Translators: Our local app
46+
'tree',
47+
)
48+
49+
MIDDLEWARE_CLASSES = (
50+
'django.contrib.sessions.middleware.SessionMiddleware',
51+
'django.middleware.common.CommonMiddleware',
52+
'django.middleware.csrf.CsrfViewMiddleware',
53+
'django.contrib.auth.middleware.AuthenticationMiddleware',
54+
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
55+
'django.contrib.messages.middleware.MessageMiddleware',
56+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
57+
)
58+
59+
ROOT_URLCONF = 'example.urls'
60+
61+
WSGI_APPLICATION = 'example.wsgi.application'
62+
63+
64+
# Database
65+
# https://docs.djangoproject.com/en/1.7/ref/settings/#databases
66+
67+
DATABASES = {
68+
'default': {
69+
'ENGINE': 'django.db.backends.sqlite3',
70+
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
71+
}
72+
}
73+
74+
# Internationalization
75+
# https://docs.djangoproject.com/en/1.7/topics/i18n/
76+
77+
LANGUAGE_CODE = 'en-us'
78+
79+
TIME_ZONE = 'UTC'
80+
81+
USE_I18N = True
82+
83+
USE_L10N = True
84+
85+
USE_TZ = True
86+
87+
88+
# Static files (CSS, JavaScript, Images)
89+
# https://docs.djangoproject.com/en/1.7/howto/static-files/
90+
91+
STATIC_URL = '/static/'

example/example/urls.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from django.conf.urls import patterns, include, url
2+
from django.contrib import admin
3+
4+
urlpatterns = patterns('',
5+
# Examples:
6+
# url(r'^$', 'example.views.home', name='home'),
7+
# url(r'^blog/', include('blog.urls')),
8+
9+
url(r'^admin/', include(admin.site.urls)),
10+
)

example/example/wsgi.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""
2+
WSGI config for example project.
3+
4+
It exposes the WSGI callable as a module-level variable named ``application``.
5+
6+
For more information on this file, see
7+
https://docs.djangoproject.com/en/1.7/howto/deployment/wsgi/
8+
"""
9+
10+
import os
11+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
12+
13+
from django.core.wsgi import get_wsgi_application
14+
application = get_wsgi_application()

example/manage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/usr/bin/env python
2+
import os
3+
import sys
4+
5+
if __name__ == "__main__":
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings")
7+
8+
from django.core.management import execute_from_command_line
9+
10+
execute_from_command_line(sys.argv)

example/tree/__init__.py

Whitespace-only changes.

example/tree/admin.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from django.contrib import admin
2+
from polymorphic_tree.admin import PolymorphicMPTTParentModelAdmin, PolymorphicMPTTChildModelAdmin
3+
from . import models
4+
5+
6+
# The common admin functionality for all derived models:
7+
8+
class BaseChildAdmin(PolymorphicMPTTChildModelAdmin):
9+
GENERAL_FIELDSET = (None, {
10+
'fields': ('parent', 'title'),
11+
})
12+
13+
base_model = models.BaseTreeNode
14+
base_fieldsets = (
15+
GENERAL_FIELDSET,
16+
)
17+
18+
19+
# Optionally some custom admin code
20+
21+
class TextNodeAdmin(BaseChildAdmin):
22+
pass
23+
24+
25+
# Create the parent admin that combines it all:
26+
27+
class TreeNodeParentAdmin(PolymorphicMPTTParentModelAdmin):
28+
base_model = models.BaseTreeNode
29+
child_models = (
30+
(models.CategoryNode, BaseChildAdmin),
31+
(models.TextNode, TextNodeAdmin), # custom admin allows custom edit/delete view.
32+
(models.ImageNode, BaseChildAdmin),
33+
)
34+
35+
list_display = ('title', 'actions_column',)
36+
37+
admin.site.register(models.BaseTreeNode, TreeNodeParentAdmin)
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import models, migrations
5+
import polymorphic_tree.models
6+
7+
8+
class Migration(migrations.Migration):
9+
10+
dependencies = [
11+
('contenttypes', '0001_initial'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='BaseTreeNode',
17+
fields=[
18+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
19+
('lft', models.PositiveIntegerField(editable=False, db_index=True)),
20+
('rght', models.PositiveIntegerField(editable=False, db_index=True)),
21+
('tree_id', models.PositiveIntegerField(editable=False, db_index=True)),
22+
('level', models.PositiveIntegerField(editable=False, db_index=True)),
23+
('title', models.CharField(max_length=200, verbose_name='Title')),
24+
],
25+
options={
26+
'verbose_name': 'Tree node',
27+
'verbose_name_plural': 'Tree nodes',
28+
},
29+
bases=(models.Model,),
30+
),
31+
migrations.CreateModel(
32+
name='CategoryNode',
33+
fields=[
34+
('basetreenode_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='tree.BaseTreeNode')),
35+
('opening_title', models.CharField(max_length=200, verbose_name='Opening title')),
36+
('opening_image', models.ImageField(upload_to='images', null=True, verbose_name='Opening image', blank=True)),
37+
],
38+
options={
39+
'verbose_name': 'Category node',
40+
'verbose_name_plural': 'Category nodes',
41+
},
42+
bases=('tree.basetreenode',),
43+
),
44+
migrations.CreateModel(
45+
name='ImageNode',
46+
fields=[
47+
('basetreenode_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='tree.BaseTreeNode')),
48+
('image', models.ImageField(upload_to='images', verbose_name='Image')),
49+
],
50+
options={
51+
'verbose_name': 'Image node',
52+
'verbose_name_plural': 'Image nodes',
53+
},
54+
bases=('tree.basetreenode',),
55+
),
56+
migrations.CreateModel(
57+
name='TextNode',
58+
fields=[
59+
('basetreenode_ptr', models.OneToOneField(parent_link=True, auto_created=True, primary_key=True, serialize=False, to='tree.BaseTreeNode')),
60+
('extra_text', models.TextField(verbose_name='Extra text')),
61+
],
62+
options={
63+
'verbose_name': 'Text node',
64+
'verbose_name_plural': 'Text nodes',
65+
},
66+
bases=('tree.basetreenode',),
67+
),
68+
migrations.AddField(
69+
model_name='basetreenode',
70+
name='parent',
71+
field=polymorphic_tree.models.PolymorphicTreeForeignKey(related_name='children', verbose_name='parent', blank=True, to='tree.BaseTreeNode', null=True),
72+
preserve_default=True,
73+
),
74+
migrations.AddField(
75+
model_name='basetreenode',
76+
name='polymorphic_ctype',
77+
field=models.ForeignKey(related_name=b'polymorphic_tree.basetreenode_set', editable=False, to='contenttypes.ContentType', null=True),
78+
preserve_default=True,
79+
),
80+
]

example/tree/migrations/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)