Skip to content

Commit

Permalink
Add before_create_obj hook to BatchCreateMutation
Browse files Browse the repository at this point in the history
  • Loading branch information
hansegucker committed Apr 17, 2024
1 parent 3bdb239 commit 89ae9ec
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions graphene_django_cud/mutations/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,10 @@ def upsert_obj(
Model,
)

@classmethod
def before_create_obj(cls, info, input, obj):
return None

@classmethod
def create_obj(
cls,
Expand Down Expand Up @@ -378,7 +382,7 @@ def create_obj(
model_field_values[name + "_id"] = obj_id

# Foreign keys are added, we are ready to create our object
obj = Model.objects.create(**model_field_values)
obj = Model(**model_field_values)

# Handle one to one rels
if len(one_to_one_rels) > 0:
Expand All @@ -402,13 +406,16 @@ def create_obj(
else:
extra_data = one_to_one_extras.get(name, {})

# This is a nested field we need to take care of.
# This is a nested fselfield we need to take care of.
value[field.field.name] = obj.pk
new_value = cls.create_or_update_one_to_one_relation(obj, field, value, extra_data, info)

setattr(obj, name, new_value)

obj.save()

cls.before_create_obj(info, input, obj)

obj.save()

# Handle extras fields
for name, extras in many_to_many_extras.items():
Expand Down

0 comments on commit 89ae9ec

Please sign in to comment.