Changes between Version 1 and Version 2 of Ticket #34884, comment 1
- Timestamp:
- Sep 29, 2023, 7:21:12 PM (14 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #34884, comment 1
v1 v2 12 12 def patched_get_or_create(self, defaults=None, **kwargs): 13 13 result, created = original_get_or_create(self, defaults=defaults, **kwargs) 14 if defaults is not None andcreated:15 for key, value in defaults.items():14 if not created: 15 for key, value in kwargs.items(): 16 16 if isinstance(result._meta.get_field(key), ForeignKey): 17 17 # isinstance handles OneToOneField also. 18 18 setattr(result, key, value) 19 for key, value in kwargs.items():20 if isinstance(result._meta.get_field(key), ForeignKey):21 # isinstance handles OneToOneField also.22 setattr(result, key, value)23 19 return result, created 24 20 … … 37 33 In [17]: def patched_get_or_create(self, defaults=None, **kwargs): 38 34 ...: result, created = original_get_or_create(self, defaults=defaults, **kwargs) 39 ...: if defaults is not None andcreated:40 ...: for key, value in defaults.items():35 ...: if not created: 36 ...: for key, value in kwargs.items(): 41 37 ...: if isinstance(result._meta.get_field(key), ForeignKey): 42 38 ...: # isinstance handles OneToOneField also. 43 39 ...: setattr(result, key, value) 44 ...: for key, value in kwargs.items():45 ...: if isinstance(result._meta.get_field(key), ForeignKey):46 ...: # isinstance handles OneToOneField also.47 ...: setattr(result, key, value)48 40 ...: return result, created 49 41 ...: