You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using django-rest-framework and in a template I want to limit what a user can do by showing or not showing according action (a button) based on users permissions. It's a detail view showing all the child records. A user can edit the child record, if the user is the creator or the creators supervisor.
Hence in the predicates I compare current user to child record creator or supervisor. The predicates and rules work as expected.
The issue I'm facing is that when the permission is checked in the template and my predicates are called, the child record is passed in as OrderedDict and not as instance of it's model class. I suspect this is due to looping child instances in the template and the child instances are actually from a nested serializer? I'm speculating.
My current hack is to simply type-check inside the predicate.
Questions is, how can I solve this nicely? or what am I doing wrong?
The text was updated successfully, but these errors were encountered:
How do you make the comparison? Most of the times, and in this case in particular, it's best to compare the natural keys of the objects (usually the id attribute, but could be anything), instead of the object references. That is, instead of user is supervisor, it would be best if the check was user.id == supervisor.id
I'm using django-rest-framework and in a template I want to limit what a user can do by showing or not showing according action (a button) based on users permissions. It's a detail view showing all the child records. A user can edit the child record, if the user is the creator or the creators supervisor.
Hence in the predicates I compare current user to child record creator or supervisor. The predicates and rules work as expected.
The issue I'm facing is that when the permission is checked in the template and my predicates are called, the child record is passed in as
OrderedDict
and not as instance of it's model class. I suspect this is due to looping child instances in the template and the child instances are actually from a nested serializer? I'm speculating.My current hack is to simply type-check inside the predicate.
Questions is, how can I solve this nicely? or what am I doing wrong?
The text was updated successfully, but these errors were encountered: