add django restframework serializer for activities
See original GitHub issueright now serializing enriched data is very complex and requires lot of knowledge of how DRF works (and probably some smart tricks to support nested data / dynamic model serialization).
We should write a basic serializer class to make this easier and write a few example for aggregated/notification and simple activity serialization.
eg.
"is_seen": false,
"is_read": false,
"group": "19931_2016-04-04",
"created_at": "2016-04-04T08:53:42.601",
"updated_at": "2016-04-04T11:33:26.140",
"id": "0bc8c85a-fa59-11e5-8080-800005683205",
"verb": "message",
"activities": [
{
"origin": null,
"verb": "message",
"time": "2016-04-04T11:33:26.140",
"id": "0bc8c85a-fa59-11e5-8080-800005683205",
"foreign_id": "chat.Message:6",
"target": null,
"to": [
"notification:1"
],
"actor": "auth.User:1",
"object": "chat.Message:6"
}
Issue Analytics
- State:
- Created 7 years ago
- Reactions:5
- Comments:10 (2 by maintainers)
Top Results From Across the Web
Tutorial 1: Serialization - Django REST framework
We can do this by declaring serializers that work very similar to Django's forms. Create a file in the snippets directory named serializers.py...
Read more >Django Activity Stream with Django REST Framework
With serializers like that, we can add a simple model mixin that allows us to query the activity stream items for a specific...
Read more >Serializers - Django REST Framework - GeeksforGeeks
Serializers in Django REST Framework are responsible for converting objects into data types understandable by javascript and front-end ...
Read more >Django REST Framework: adding additional field to ...
You can change your model method to property and use it in serializer with this approach. class ...
Read more >How to create a REST API with Django REST framework
Django REST framework (DRF) is a powerful and flexible toolkit for building Web APIs. Its main benefit is that it makes serialization much ......
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 Free
Top 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
I’d be very interested in any developments with this enhancement. I’ve already built out my rest API with DRF and was having a hard time integrating it with stream. Looking forward to any updates! Thanks!
Your code helped me get started but I was on course to dig into flat feeds. I think how stream’s code is built it works differently for flat versus aggregated. Specifically it seems in terms of how I think for aggregated it gives you “activities” whereas for flat feeds I just see EnrichedActivity with an activity_data member variable. Feel free to point out if that’s not right. Wouldn’t be surprised at all if you had to change your code if you still use stream since that was 2016.
I tried looking through:
https://github.com/morenoh149/django-rest-framework-getstream/blob/0446e410b1a9f440f96989d3c98529e4316e1367/snippets/serializers.py
For if they had given us a way to access the activity data directly to be able to serialize it and I was unable to identify if an accessor had been provided in stream_django. I don’t like it but I ended up having to access the member variable directly with the activity data. Even though Tom said he thought we would have issues with DRF I know exactly what I still want to do there but the issue is getting the right data out of stream’s classes.
I had their EnrichedActivity(collections.MutableMapping) object in the list returned by:
enriched_activities = enricher.enrich_activities(activities)
and did:
and pulled the data back out that I wanted to serialize. If they could dig through a better solution for us for flat feeds that would be ideal. Or just resolve it in general. I’d rather not leave it the way it is. I tried using the
__get__
methods but I think those are for specific keys and not entire activity items. Would need a method in stream_django that returns the activity item inside EnrichedActivity. Feel that could be the best bet so I can build my result list and serialize what I want but could need more discussion. @tbarbugli @pterkPS. I don’t want to be forced to use something like:
as the way that I have to serialize my objects. I should be able to have full control on how to serialize my objects irrelevant to how stream has “activities”. If I want to add other layers to my serialization steps it should be extendable and allowed via stream. Right now I’m taking fields out of the activity data itself and choosing to return serialized data in the fashion I desire. Maybe I’m alone here but we’ll see if others agree. Certainly seems how you build good code, especially in the Django world: loose coupling.