Skip to content

Commit 9793a5e

Browse files
committed
Converted CustomForeignKeyField into an importable non-dynamic class
1 parent a05d5b7 commit 9793a5e

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

simple_history/models.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def copy_fields(self, model):
147147
# Don't allow reverse relations.
148148
# ForeignKey knows best what datatype to use for the column
149149
# we'll used that as soon as it's finalized by copying rel.to
150-
field.__class__ = get_custom_fk_class(type(field))
150+
field.__class__ = CustomForeignKeyField
151151
field.rel.related_name = '+'
152152
field.null = True
153153
field.blank = True
@@ -240,7 +240,8 @@ def get_history_user(self, instance):
240240
return None
241241

242242

243-
class ForeignKeyMixin(object):
243+
class CustomForeignKeyField(models.ForeignKey):
244+
244245
def get_attname(self):
245246
return self.name
246247

@@ -309,10 +310,6 @@ def contribute_to_class(self, cls, name):
309310
RelatedField.contribute_to_class(self, cls, name)
310311

311312

312-
def get_custom_fk_class(parent_type):
313-
return type(str('CustomForeignKey'), (ForeignKeyMixin, parent_type), {})
314-
315-
316313
def transform_field(field):
317314
"""Customize field appropriately for use in historical model"""
318315
field.name = field.attname

0 commit comments

Comments
 (0)