-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API: Récupérer des WasteActions avec leur ResourceActions (si l'utilisateur est connecté) #4544
base: staging
Are you sure you want to change the base?
Conversation
e536a78
to
3f9d008
Compare
69a04c9
to
5261f51
Compare
5261f51
to
b38801c
Compare
b38801c
to
469dfe4
Compare
@@ -39,3 +39,10 @@ class WasteActionView(RetrieveAPIView): | |||
model = WasteAction | |||
queryset = WasteAction.objects.all() | |||
serializer_class = WasteActionSerializer | |||
|
|||
def get_serializer(self, *args, **kwargs): | |||
if self.request.user.is_authenticated: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
vu qu'on a besoin de passer le user au serializer, je n'ai pas trouvé mieux que les kwargs (j'ai vu que c'était déjà utilisé ailleurs (canteen, "action"))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
est-ce que c'est possible de passer actions directe ? C'est-à-dire mettre la logique de user et queryset qui est maintenant dans le serializer ici ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
j'ai essayé mais je n'arrive pas à filtrer le queryset de la FK.
ici dans le vue ca permet seulement de filtrer le queryset de WasteAction, pas ResourceAction.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mais en fait ca bloque sur le fait que je n'arrive pas à passer un queryset custom à serializer custom 🤔
le queryset custom dans WasteActionWithActionsSerializer pour le champ actions est ignoré..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok je crois que j'ai trouvé une solution avec SerializerMethodField
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
finally : cd8b85a
data/models/resourceaction.py
Outdated
@@ -5,12 +5,19 @@ | |||
from .wasteaction import WasteAction | |||
|
|||
|
|||
class ResourceActionQuerySet(models.QuerySet): | |||
def for_user(self, user): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
si vous trouvez un meilleur nom de for_user
let me know ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for_managed_canteens
/for_user_canteens
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
renommé ici : 111a86d
self.assertTrue("actions" in response.data) | ||
self.assertEqual(len(response.data["actions"]), 1) | ||
self.assertEqual(response.data["actions"][0]["canteen_id"], self.canteen.id) | ||
self.assertEqual(response.data["actions"][0]["canteen"]["id"], self.canteen.id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pourquoi avoir les deux canteen_id
et canteen: {id}
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
le serializer ResourceActionWithCanteenSerializer hérite de ResourceActionSerializer du coup il a les deux (l'id, et l'objet). ca ne me choque pas ^^
7d0dd34
to
cd8b85a
Compare
Quoi ?
Suite de #4500
On améliore l'endpoint API existant
wasteActions/<int:pk>
, en rajoutant un champactions
si l'utilisateur est connecté.Ce champ contient une liste des ResourceAction existantes pour les cantines auxquelles l'utilisateur appartient.
Pour cela