type object 'X' has no attribute 'objects'

前端 未结 3 2037
情书的邮戳
情书的邮戳 2020-12-18 18:11

I am using Django and Django Rest Framework 2.4.0

I get the Attribute error type object \'Notification\' has no attribute \'objects\'

mo

3条回答
  •  梦毁少年i
    2020-12-18 18:25

    Add objects = models.Manager() to your model, or any other custom manager that you are using and/or define.

    class Notification(models.Model):
        NOTIFICATION_ID = models.AutoField(primary_key=True)
        user = models.ForeignKey(User, related_name='user_notification')
        type = models.ForeignKey(NotificationType)
        join_code = models.CharField(max_length=10, blank=True)
        requested_userid = models.CharField(max_length=25, blank=True)
        datetime_of_notification = models.DateTimeField()
        is_active = models.BooleanField(default=True)
    
        objects = models.Manager()
    

提交回复
热议问题