in_built 장고 사용자를 사용하고 추가 된 각 사용자에 대해 알림을 생성하려고하지만 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 요청을 할 때마다 사용자 인스턴스를 저장하고 그래서 Notification 객체를 생성합니다. 새로운 사용자가 생성 될 때만 Notification을 만들고 싶습니다.