Skip to content

Commit

Permalink
Shorten kwargs setup
Browse files Browse the repository at this point in the history
  • Loading branch information
cb109 committed Dec 9, 2020
1 parent 8723a96 commit cef7415
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions model_bakery/baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,11 +541,10 @@ def generate_value(self, field: Field, commit: bool = True) -> Any:
# Pass instance instead of pk/<to_field> value. In case a
# custom 'to_field' is set, Django should populate
# field.to_fields with a single string.
key = "pk"
default_key = "pk"
if field.to_fields and field.to_fields[0] is not None:
key = field.to_fields[0]
instance_kwargs = {key: default}
default = remote_field.model.objects.get(**instance_kwargs)
default_key = field.to_fields[0]
default = remote_field.model.objects.get(**{default_key: default})
return default
elif field.name in self.attr_mapping:
generator = self.attr_mapping[field.name]
Expand Down

0 comments on commit cef7415

Please sign in to comment.