Skip to content

Commit

Permalink
Merge pull request #143 from druids/FixFileFieldChanges
Browse files Browse the repository at this point in the history
Fixe changed fields for file field
  • Loading branch information
matllubos authored Dec 21, 2022
2 parents f367c97 + 946a13c commit 5cbc0fe
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions chamber/models/changed_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
from chamber.utils.decorators import singleton


def _should_exclude_field(field, fields, exclude):
return (fields and field.name not in fields) or (exclude and field.name in exclude)
def _should_exclude_field(field_name, fields, exclude):
return (fields and field_name not in fields) or (exclude and field_name in exclude)


def field_value_from_instance(field, instance):
Expand Down Expand Up @@ -46,12 +46,19 @@ def __bool__(self):
Deferred = DeferredSingleton()


def unknown_model_fields_to_dict(instance, fields=None, exclude=None):
def get_model_fields(model):
return [field for field in model._meta.concrete_fields] # pylint: disable=W0212


def get_model_field_names(model):
return [field.name for field in get_model_fields(model)]


def unknown_model_fields_to_dict(instance, fields=None, exclude=None):
return {
field.name: Unknown
for field in instance._meta.concrete_fields # pylint: disable=W0212
if not _should_exclude_field(field, fields, exclude)
field_name: Unknown
for field_name in get_model_field_names(instance)
if not _should_exclude_field(field_name, fields, exclude)
}


Expand All @@ -60,9 +67,9 @@ def model_to_dict(instance, fields=None, exclude=None):
The same implementation as django model_to_dict but editable fields are allowed
"""
return {
field.name: field_value_from_instance(field, instance)
for field in instance._meta.concrete_fields # pylint: disable=W0212
if not _should_exclude_field(field, fields, exclude)
field.name: copy.deepcopy(field_value_from_instance(field, instance))
for field in get_model_fields(instance) # pylint: disable=W0212
if not _should_exclude_field(field.name, fields, exclude)
}


Expand Down

0 comments on commit 5cbc0fe

Please sign in to comment.