Skip to content

Commit 2ee1427

Browse files
author
Andy Babic
committed
Support exclude_fields in ClusterableModel.from_serializable_data() and ClusterableModel.from_json()
1 parent 8acbc18 commit 2ee1427

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

modelcluster/models.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def to_json(self):
263263
return json.dumps(self.serializable_data(), cls=DjangoJSONEncoder)
264264

265265
@classmethod
266-
def from_serializable_data(cls, data, check_fks=True, strict_fks=False):
266+
def from_serializable_data(cls, data, check_fks=True, strict_fks=False, exclude_fields=None):
267267
"""
268268
Build an instance of this model from the JSON-like structure passed in,
269269
recursing into related objects as required.
@@ -275,7 +275,7 @@ def from_serializable_data(cls, data, check_fks=True, strict_fks=False):
275275
in which case any dangling foreign keys with on_delete=CASCADE will cause None to be
276276
returned for the entire object.
277277
"""
278-
obj = model_from_serializable_data(cls, data, check_fks=check_fks, strict_fks=strict_fks)
278+
obj = model_from_serializable_data(cls, data, check_fks=check_fks, strict_fks=strict_fks, exclude_fields=exclude_fields)
279279
if obj is None:
280280
return None
281281

@@ -307,8 +307,8 @@ def from_serializable_data(cls, data, check_fks=True, strict_fks=False):
307307
return obj
308308

309309
@classmethod
310-
def from_json(cls, json_data, check_fks=True, strict_fks=False):
311-
return cls.from_serializable_data(json.loads(json_data), check_fks=check_fks, strict_fks=strict_fks)
310+
def from_json(cls, json_data, check_fks=True, strict_fks=False, exclude_fields=None):
311+
return cls.from_serializable_data(json.loads(json_data), check_fks=check_fks, strict_fks=strict_fks, exclude_fields=exclude_fields)
312312

313313
@transaction.atomic
314314
def copy_child_relation(self, child_relation, target, commit=False, append=False):

0 commit comments

Comments
 (0)