Skip to content

Commit

Permalink
Merge pull request #130 from hansegucker/before-create-obj-hook
Browse files Browse the repository at this point in the history
Add before_create_obj hook to BatchCreateMutation
  • Loading branch information
tOgg1 authored Jun 6, 2024
2 parents 3bdb239 + 2152f12 commit 9d49c14
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions graphene_django_cud/mutations/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ 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)

cls.before_create_obj(info, input, obj)

obj.save()

# Handle one to one rels
if len(one_to_one_rels) > 0:
Expand Down Expand Up @@ -408,8 +412,6 @@ def create_obj(

setattr(obj, name, new_value)

obj.save()

# Handle extras fields
for name, extras in many_to_many_extras.items():
field = Model._meta.get_field(name)
Expand Down Expand Up @@ -757,6 +759,10 @@ def before_save(cls, root, info, *args, **kwargs):
def after_mutate(cls, root, info, *args, **kwargs):
return None

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

@classmethod
def resolve_id(cls, id):
return disambiguate_id(id)
Expand Down

0 comments on commit 9d49c14

Please sign in to comment.