Closed maciejurm closed 5 years ago
This is not related to actstream
at all. Your method my_handler()
does not know what request
is, and how should it, there simply is no request in that context. You are doing this wrong. A request and its associated User is part of the view layer, not the model, you must add your signal handler there.
Hi, I try to add request.user like documentation said:
action.send(request.user, verb='joined', target=group)
But when I add request.user to signal and try to save object error appear: "name 'request' is not defined". User model in app.py is registered.
My model and signal: `class Subject(models.Model): title = models.CharField(max_length=255) embed = models.URLField(max_length=255, blank=True, null=True) slug = AutoSlugField(populate_from='title', unique=True) body = models.TextField() image = models.ImageField(upload_to='subject') author = models.ForeignKey(User, on_delete=models.CASCADE) active = models.BooleanField(default=True) created_at = models.DateTimeField(auto_now_add=True) board = models.ForeignKey(Board, on_delete=models.CASCADE, related_name='subjects')
def my_handler(sender, instance, created, **kwargs): action.send(request.user, instance, verb='dodał post')
post_save.connect(my_handler, sender=Subject)`