56π
The line notifications = Notification.objects.all()
is referencing the Notification
View class defined in api.py and not models.py.
The easiest way to fix this error is to rename the Notification
class in either api.py or models.py so that you can refer to your model properly. Another option would be to use named imports:
from .models import Notification as NotificationModel
class Notification(generics.ListAPIView):
...
def get_queryset(self):
notifications = NotificationModel.objects.all()
...
π€Derek Kwok
33π
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()
π€Paul Tuckett
- [Django]-Django rest framework, use different serializers in the same ModelViewSet
- [Django]-Django gives Bad Request (400) when DEBUG = False
- [Django]-Django 'objects.filter()' with list?
1π
Not the answer to this question but if you have come via Google you may have accidentally marked your model as abstract and are trying to query it directly, in which case you need to remove:
class Meta:
abstract = True
π€Cam Rail
- [Django]-How to make Django QuerySet bulk delete() more efficient
- [Django]-Django β after login, redirect user to his custom page β> mysite.com/username
- [Django]-Can't connect to local MySQL server through socket '/tmp/mysql.sock
Source:stackexchange.com