Fix migration issues, tests, and templates

This commit is contained in:
Wayne Witzel III
2017-11-09 17:24:54 -05:00
parent 6d6bbbb627
commit 96904968d8
21 changed files with 346 additions and 419 deletions
+2 -2
View File
@@ -450,7 +450,7 @@ def copy_model_by_class(obj1, Class2, fields, kwargs):
elif not isinstance(Class2._meta.get_field(field_name), (ForeignObjectRel, ManyToManyField)):
create_kwargs[field_name] = kwargs[field_name]
elif hasattr(obj1, field_name):
field_obj = obj1._meta.get_field_by_name(field_name)[0]
field_obj = obj1._meta.get_field(field_name)
if not isinstance(field_obj, ManyToManyField):
create_kwargs[field_name] = getattr(obj1, field_name)
@@ -471,7 +471,7 @@ def copy_m2m_relationships(obj1, obj2, fields, kwargs=None):
'''
for field_name in fields:
if hasattr(obj1, field_name):
field_obj = obj1._meta.get_field_by_name(field_name)[0]
field_obj = obj1._meta.get_field(field_name)
if isinstance(field_obj, ManyToManyField):
# Many to Many can be specified as field_name
src_field_value = getattr(obj1, field_name)
+13
View File
@@ -6,6 +6,7 @@ from django.db.migrations.loader import MigrationLoader
from django.db import connection
# Python
from itertools import chain
import re
@@ -20,3 +21,15 @@ def get_tower_migration_version():
if migration_version > v:
v = migration_version
return v
def get_all_field_names(model):
# Implements compatibility with _meta.get_all_field_names
# See: https://docs.djangoproject.com/en/1.11/ref/models/meta/#migrating-from-the-old-api
return list(set(chain.from_iterable(
(field.name, field.attname) if hasattr(field, 'attname') else (field.name,)
for field in model._meta.get_fields()
# For complete backwards compatibility, you may want to exclude
# GenericForeignKey from the results.
if not (field.many_to_one and field.related_model is None)
)))