Skip to content

Commit

Permalink
Merge pull request #184 from raphaelmerx/example_migrate
Browse files Browse the repository at this point in the history
Migrate the example to Django 1.10
  • Loading branch information
mlavin committed Feb 28, 2017
2 parents d434615 + 4eefcda commit bb103b0
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 22 deletions.
9 changes: 9 additions & 0 deletions example/core/fixtures/initial_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
[
{
"model": "auth.user",
"pk": 1,
"fields": {
"is_superuser": true,
"username": "example_user",
"email": "ex@gmail.com"
}
},
{
"pk": 1,
"model": "core.fruit",
Expand Down
52 changes: 52 additions & 0 deletions example/core/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.12 on 2017-02-25 01:13
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import localflavor.us.models


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='City',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
('state', localflavor.us.models.USStateField(max_length=2)),
],
),
migrations.CreateModel(
name='Farm',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
migrations.CreateModel(
name='Fruit',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=200)),
],
),
migrations.AddField(
model_name='farm',
name='fruit',
field=models.ManyToManyField(to='core.Fruit'),
),
migrations.AddField(
model_name='farm',
name='owner',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='farms', to=settings.AUTH_USER_MODEL),
),
]
20 changes: 20 additions & 0 deletions example/core/migrations/0002_load_initial_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import migrations
from django.core.management import call_command


def load_initial_data(apps, schema_editor):
call_command('loaddata', 'initial_data', app_label='core')


class Migration(migrations.Migration):

dependencies = [
('core', '0001_initial')
]

operations = [
migrations.RunPython(load_initial_data),
]
Empty file.
13 changes: 7 additions & 6 deletions example/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url

from .views import formset, advanced, index

urlpatterns = patterns('core.views',
url(r'^formset/', 'formset', name='example-formset'),
url(r'^advanced/', 'advanced', name='example-advanced'),
url(r'^', 'index', name='example-index'),
)
urlpatterns = [
url(r'^formset/', formset, name='example-formset'),
url(r'^advanced/', advanced, name='example-advanced'),
url(r'^', index, name='example-index'),
]
9 changes: 4 additions & 5 deletions example/core/views.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import pprint

from django.shortcuts import render_to_response
from django.template import RequestContext
from django.shortcuts import render

from core.forms import FruitForm, ChainedForm, FarmFormset

Expand All @@ -28,7 +27,7 @@ def index(request):
'form': form,
'raw_post': raw_post
}
return render_to_response('base.html', context, context_instance=RequestContext(request))
return render(request, 'base.html', context)


def advanced(request):
Expand All @@ -41,7 +40,7 @@ def advanced(request):
else:
form = ChainedForm()

return render_to_response('advanced.html', {'form': form}, context_instance=RequestContext(request))
return render(request, 'advanced.html', {'form': form})


def formset(request):
Expand All @@ -54,4 +53,4 @@ def formset(request):
else:
formset = FarmFormset()

return render_to_response('formset.html', {'formset': formset}, context_instance=RequestContext(request))
return render(request, 'formset.html', {'formset': formset})
26 changes: 22 additions & 4 deletions example/example/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
BASE_DIR = os.path.dirname(__file__)

DEBUG = True
TEMPLATE_DEBUG = DEBUG

DATABASES = {
'default': {
Expand Down Expand Up @@ -87,9 +86,28 @@
# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'example.wsgi.application'

TEMPLATE_DIRS = (
os.path.join(BASE_DIR, 'templates'),
)
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
os.path.join(BASE_DIR, 'templates'),
],
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.media',
'django.template.context_processors.request',
'django.template.context_processors.i18n',
'django.template.context_processors.static',
],
'loaders': [
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
]
},
},
]

INSTALLED_APPS = (
'django.contrib.auth',
Expand Down
13 changes: 6 additions & 7 deletions example/example/urls.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
from django.conf.urls import patterns, include, url
from django.conf.urls import include, url

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
urlpatterns = [
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),

# Uncomment the next line to enable the admin:
(r'^admin/', include(admin.site.urls)),
(r'^selectable/', include('selectable.urls')),
(r'^', include('core.urls')),
)
url(r'^admin/', include(admin.site.urls)),
url(r'^selectable/', include('selectable.urls')),
url(r'^', include('core.urls')),
]
Empty file modified example/manage.py
100644 → 100755
Empty file.

0 comments on commit bb103b0

Please sign in to comment.