Hyperlinking to a filtered list

2 views
Skip to first unread message

Brian Stempin

unread,
Oct 17, 2016, 5:23:54 PM10/17/16
to Django REST framework
Hi,
I'm trying to hyperlink to a filtered list.  Let's say I have these resources:  User and Transaction.  A User has many Transactions, and each Transaction has exactly one User.  Because a User could have hundreds of transactions, I don't want the user to serialize like this:

[{"id": 1, "transactions": [ hundreds of transaction URLs here ]}]

but rather like this:

[{"id": 1, "transactions": "http://server/transactions?user=1" }]

This way, the REST client could follow the URL and even apply additional filtering if it so desired.

Is there an easy way to do this?  I seem to not be having any luck with HyperlinkedRelatedField.

Thanks,
Brian

Xavier Ordoquy

unread,
Oct 18, 2016, 1:22:02 AM10/18/16
to django-res...@googlegroups.com
Hi,
I don’t think you could have an out of the box solution for it.
You need knowledge of the entry point url and the filter name.
The best solution I can think of being to make a property out of a function in the User that reverse the entry point url and add the filter yourself.

Regards,
Xavier,
Linovia.
Reply all
Reply to author
Forward
0 new messages