-
Notifications
You must be signed in to change notification settings - Fork 766
Closed
Labels
Description
I created the following class to update the post in spesfic conditions but if the contitions ==False the I need to return {"message": "Only the owner of the post and the admin(website's wonr) can edit and delet this post"} But the JsonResponse don't work likt it is with RestFramework!
class UpdatePost(graphene.Mutation):
# owner(added_by)+admin can update and delete
class Arguments:
id = graphene.Int(required=True)
description = graphene.String()
post = graphene.Field(schema.Posts)
@classmethod
def mutate(cls, root, info, id, description):
post = models.Post.objects.get(id=id)
if (info.context.user == post.added_by):
post.description = description
post.save()
return CreatePost(post=post)
else:
JsoneResponse({"message": "Only the owner of the post and the admin(website's wonr) can edit and delet this post"})
[code source on stackoveflow](https://stackoverflow.com/posts/66624122/edit)