From 7a5787198c9ac33b7a76d54be683d718ca9d51c7 Mon Sep 17 00:00:00 2001 From: Viggo de Vries Date: Fri, 23 Aug 2024 14:01:33 +0200 Subject: [PATCH] Fixes a weird issue where overridden mappings and resource will stay none when replacing them in projects --- oscar_odin/mappings/_common.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/oscar_odin/mappings/_common.py b/oscar_odin/mappings/_common.py index fb32181..ce87d93 100644 --- a/oscar_odin/mappings/_common.py +++ b/oscar_odin/mappings/_common.py @@ -32,4 +32,20 @@ def map_queryset( class OscarBaseMapping(MappingBase, metaclass=MappingMeta): + def create_object(self, **field_values): + """Create an instance of target object, this method can be customised to handle + custom object initialisation. + + :param field_values: Dictionary of values for creating the target object. + """ + try: + new_obj = self.to_obj() # pylint: disable=E1102 + + for key, field_value in field_values.items(): + setattr(new_obj, key, field_value) + + return new_obj + except AttributeError: + return super().create_object(**field_value) + register_mapping = False