私はin_built Djangoユーザーを使用しており、追加されたユーザーごとに通知を生成したいのですが、put
リクエストで通知を生成したくありません。post
リクエストでのみ生成する必要があります。 私のモデルは....どうすればdjangoでputメソッドとpostメソッドを区別できるシグナルを作ることができますか?
Models.py
class User(AbstractUser):
gender= models.CharField(choices=GENDER, max_length=10, null=True, blank=True)
role= models.CharField(choices=ROLE_CHOICE, max_length=15, null=True, blank=True)
designation=models.CharField(max_length=225,null=True,blank=True)
employee_id = models.CharField(max_length=20, default=None, null=True)
class Notification(models.Model):
text = models.CharField(max_length=225)
recipient=models.ForeignKey(User,related_name='notification')
timestamp = models.DateTimeField(null=True,blank=True,auto_now_add=True)
unread = models.BooleanField(default=True, blank=False)
send_by= models.ForeignKey(User, null=True,blank=True, related_name='Notification')
と私は次のように行われてきた私の信号で ...
@receiver(post_save, sender= Any_model)
def comment_recieved(sender,**kwargs):
obj= kwargs.get('instance')
recipient=User.objects.get(is_superuser=True)
Notification.objects.create(
recipient= recipient,
comment= obj,
project=obj.project,
type="commented",
send_by=obj.supporter,
text= "%s has commented on %s" % (obj.supporter, obj.project)
)
return None
Signals.py
です
問題は、put要求またはpost要求を行うたびに、ユーザーインスタンスと通知オブジェクトを作成します。新しいユーザーが作成されたときにのみ通知を作成します。