Serializing the django-notifications Model
See original GitHub issueI’m trying to serialize the model included in django-notifications package with DRF (for a RESTFUL API)
But i’m facing a problem. When I acces the model Notification inside notifications\models.py and try to make a ModelSerializer of it, then raise this error:
NotificationQuerySet' object has no attribute 'recipient'.
My ModelSerializer:
class NotificationSerializer(serializers.ModelSerializer):
class Meta:
model = Notification
fields = ('description', 'recipient',)
Any tip on this? I don’t understand why is trying to accesing NotificationQuerySet instead of Notification model…
Thanks in andvance.
Issue Analytics
- State:
- Created 8 years ago
- Reactions:4
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Serializing NotificationQuerySet from django-notifications-hq ...
So, i'm trying to add to my API made with DRF (Django REST Framework) the notifications Model ...
Read more >Django Notifications - velog
Serializing the django -notifications Model · Inheriting the AbstractNotification model for custom fields.
Read more >Models — Django Notify 0.1 documentation
This model is pretty-much a replica of django-notifications 's model. The newly added fields just adds a feature to allow anonymous actors ,...
Read more >Serializing Django objects
Django's serialization framework provides a mechanism for “translating” Django models into other formats. Usually these other formats will be text-based and ...
Read more >Serializer relations - Django REST framework
Relational fields are used to represent model relationships. ... If AlbumSerializer is used to serialize a fairly large queryset with many=True then it ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I know this is a really old question but I solved this recently and wanted to share my solution. My solution took advantage of the generic foreign key support in django rest framework. See below:
See here - http://www.django-rest-framework.org/api-guide/relations/#generic-relationships
In this example the target object can be of type Foo or Bar and the appropriate serializer will be used.
Added the exemple in README file. Thanks @DaWy .