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 11d15b3
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 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 Down Expand Up @@ -408,7 +412,10 @@ def create_obj(

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 11d15b3

Please sign in to comment.