Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable django 1.7+ migrations to avoid issue #12 #13

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist
docs/_build
.coverage
.tox/
*.pyc

# created by the Makefile: virtualenv
bin/
Expand Down
22 changes: 8 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
language: python
python: 2.7
python:
- "2.7"
- "3.4"
- "3.5"
env:
- TOX_ENV=py26-1.3
- TOX_ENV=py26-1.4
- TOX_ENV=py26-1.5
- TOX_ENV=py26-1.6
- TOX_ENV=py27-1.3
- TOX_ENV=py27-1.4
- TOX_ENV=py27-1.5
- TOX_ENV=py27-1.6
- TOX_ENV=py27-1.7
- TOX_ENV=py33-1.5
- TOX_ENV=py33-1.6
- TOX_ENV=py33-1.7
- TOX_ENV=py34-1.7
- TOX_ENV=dj-1.5
- TOX_ENV=dj-1.6
- TOX_ENV=dj-1.7
- TOX_ENV=dj-1.8
install:
- pip install tox
script:
Expand Down
8 changes: 4 additions & 4 deletions data_exports/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ def get_readonly_fields(self, request, obj=None):
return []
return super(ExportAdmin, self).get_readonly_fields(request, obj)

def get_formsets(self, request, obj=None):
def get_formsets_with_inlines(self, request, obj=None):
if obj is None:
return
if not hasattr(self, 'inline_instances'):
self.inline_instances = self.get_inline_instances(request)
for inline in self.inline_instances:
yield inline.get_formset(request, obj)
yield inline.get_formset(request, obj), inline

def response_add(self, request, obj, post_url_continue=POST_URL_CONTINUE):
"""If we're adding, save must be "save and continue editing"
Expand All @@ -50,8 +50,8 @@ def response_add(self, request, obj, post_url_continue=POST_URL_CONTINUE):
* We are adding a user in a popup

"""
if '_addanother' not in request.POST and '_popup' not in request.POST:
request.POST['_continue'] = 1
# if '_addanother' not in request.POST and '_popup' not in request.POST:
# request.POST['_continue'] = 1
return super(ExportAdmin, self).response_add(request,
obj,
post_url_continue)
Expand Down
8 changes: 8 additions & 0 deletions data_exports/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env python
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _


class CsvExportConfig(AppConfig):
name = 'data_exports'
default_auto_field = "django.db.models.AutoField"
48 changes: 43 additions & 5 deletions data_exports/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,56 @@
from data_exports.models import Export, Column
from inspect_model import InspectModel

#####################################################################
# Monkey Patch Inspect Model
def update_fields(self):
self.fields = set()
self.relation_fields = set()
self.many_fields = set()
opts = getattr(self.model, '_meta', None)
if opts:
for field in opts.get_fields():
direct = not field.auto_created or field.concrete
if not direct: # relation or many field from another model
name = field.get_accessor_name()
field = field.field
if field.rel.multiple: # m2m or fk to this model
self._add_item(name, self.many_fields)
else: # one to one
self._add_item(name, self.relation_fields)
else: # relation, many or field from this model
name = field.name
if field.related_model: # relation or many field
if field.many_to_many: # m2m
self._add_item(name, self.many_fields)
else:
self._add_item(name, self.relation_fields)
else: # standard field
self._add_item(name, self.fields)
try:
from django.contrib.contenttypes.generic import (
GenericForeignKey)
for f in opts.virtual_fields:
if isinstance(f, GenericForeignKey):
self._add_item(f.name, self.relation_fields)
except ImportError:
pass

class ExportForm(forms.ModelForm):

class Meta:
model = Export
exclude = ()
InspectModel.update_fields = update_fields
######################################################################


class ExportForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(ExportForm, self).__init__(*args, **kwargs)
if self.instance: # don't allow modification of the model once created
del self.fields['model']

class Meta:
model = Export
exclude = ()


class ColumnForm(forms.ModelForm):
# make sure we have a select widget for the column choice
Expand Down Expand Up @@ -59,7 +97,7 @@ def get_choices(model, prefixes=[]):
for f in im.relation_fields:
related_field = getattr(model, f)
if hasattr(related_field, 'field'): # ForeignKey
related_model = related_field.field.rel.to
related_model = related_field.field.related_model
else:
related_model = related_field.related.model
if f in prefixes: # we already went through this model
Expand Down
125 changes: 65 additions & 60 deletions data_exports/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,70 @@
# encoding: utf-8
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

class Migration(SchemaMigration):
from django.db import models, migrations

def forwards(self, orm):

# Adding model 'Export'
db.create_table('data_exports_export', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('name', self.gf('django.db.models.fields.CharField')(max_length=50)),
('slug', self.gf('django.db.models.fields.SlugField')(max_length=50, db_index=True)),
('display_labels', self.gf('django.db.models.fields.BooleanField')(default=True)),
('model', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['contenttypes.ContentType'])),
))
db.send_create_signal('data_exports', ['Export'])

# Adding model 'Column'
db.create_table('data_exports_column', (
('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)),
('export', self.gf('django.db.models.fields.related.ForeignKey')(to=orm['data_exports.Export'])),
('column', self.gf('django.db.models.fields.CharField')(max_length=255)),
('label', self.gf('django.db.models.fields.CharField')(max_length=50, blank=True)),
))
db.send_create_signal('data_exports', ['Column'])
class Migration(migrations.Migration):

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

def backwards(self, orm):

# Deleting model 'Export'
db.delete_table('data_exports_export')

# Deleting model 'Column'
db.delete_table('data_exports_column')


models = {
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
},
'data_exports.column': {
'Meta': {'object_name': 'Column'},
'column': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'export': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['data_exports.Export']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'label': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'})
},
'data_exports.export': {
'Meta': {'object_name': 'Export'},
'display_labels': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}),
'slug': ('django.db.models.fields.SlugField', [], {'max_length': '50', 'db_index': 'True'})
}
}

complete_apps = ['data_exports']
operations = [
migrations.CreateModel(
name='Column',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('column', models.CharField(max_length=255)),
('label', models.CharField(max_length=255, blank=True)),
('order', models.PositiveIntegerField()),
],
options={
'ordering': ['order'],
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Export',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=50)),
('slug', models.SlugField(unique=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Format',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=50)),
('file_ext', models.CharField(max_length=10, blank=True)),
('mime', models.CharField(max_length=50)),
('template', models.CharField(max_length=255)),
],
options={
'ordering': ['name'],
},
bases=(models.Model,),
),
migrations.AddField(
model_name='export',
name='export_format',
field=models.ForeignKey(on_delete=models.CASCADE, blank=True, to='data_exports.Format', help_text='Leave empty to display as HTML', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='export',
name='model',
field=models.ForeignKey(on_delete=models.CASCADE, to='contenttypes.ContentType'),
preserve_default=True,
),
migrations.AddField(
model_name='column',
name='export',
field=models.ForeignKey(on_delete=models.CASCADE, to='data_exports.Export'),
preserve_default=True,
),
]

This file was deleted.

56 changes: 0 additions & 56 deletions data_exports/migrations/0003_auto__add_field_column_order.py

This file was deleted.

Loading