Changes between Version 1 and Version 2 of Ticket #34884, comment 1


Ignore:
Timestamp:
Sep 29, 2023, 7:21:12 PM (14 months ago)
Author:
Laurent Lyaudet

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #34884, comment 1

    v1 v2  
    1212def patched_get_or_create(self, defaults=None, **kwargs):
    1313     result, created = original_get_or_create(self, defaults=defaults, **kwargs)
    14      if defaults is not None and created:
    15          for key, value in defaults.items():
     14     if not created:
     15         for key, value in kwargs.items():
    1616             if isinstance(result._meta.get_field(key), ForeignKey):
    1717                 # isinstance handles OneToOneField also.
    1818                 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)
    2319     return result, created
    2420
     
    3733In [17]: def patched_get_or_create(self, defaults=None, **kwargs):
    3834    ...:      result, created = original_get_or_create(self, defaults=defaults, **kwargs)
    39     ...:      if defaults is not None and created:
    40     ...:          for key, value in defaults.items():
     35    ...:      if not created:
     36    ...:          for key, value in kwargs.items():
    4137    ...:              if isinstance(result._meta.get_field(key), ForeignKey):
    4238    ...:                  # isinstance handles OneToOneField also.
    4339    ...:                  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)
    4840    ...:      return result, created
    4941    ...:
Back to Top