【发布时间】:2016-06-03 07:00:52
【问题描述】:
我正在使用 Django 和 Django Rest Framework 2.4.0
我收到属性错误type object 'Notification' has no attribute 'objects'
models.py
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)
serializers.py:
class NotificationSerializer(serializers.ModelSerializer):
class Meta:
model = Notification
fields = (
'type',
'join_code',
'requested_userid',
'datetime_of_notification'
)
api.py:
class Notification(generics.ListAPIView):
serializer_class = NotificationSerializer
def get_queryset(self):
notifications = Notification.objects.all()
return notifications
谁能帮我解决这个问题?它在api.py 中的notifications = Notification.objects.all() 行失败
【问题讨论】:
标签: django django-rest-framework