How to send variables from to a signal in Django

i want django to create a ServerModeratorPermission object just after the user has been set as the moderator of the server

class ModeratorSettingsView(LoginRequiredMixin, View):
form_class = AddModeratorForm


def post(self, request, server_tag):
    form = self.form_class(request.POST)

    user = User.objects.get(pk=request.POST.get('user'))
    server = Server.objects.get(tag=server_tag)
    moderators = server.moderator_of.exclude(user=server.creator)
    moderator = ServerModerator.objects.get(user=user)
    return render(request, 'servers/moderator-settings.html', {'moderators':moderators, 'server':server, 'form':form})

@receiver(post_save, sender=ServerModerator)
    def give_default_permission(instance, *args, **kwargs):
        # i need server_tag for this query
        # server = Server.objects.get(tag=server_tag)
        moderator = ServerModerator.objects.get(
        ServerModeratorPermission.objects.create(moderator=moderator, server=server)

is there anyway to send server_tag that being used in the view class to the signal?

If server_tag is a field, try to server = Server.objects.get(tag=instance.server_tag)

Back to Top