-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Refactor filterforms in list Views #318
Comments
Tasks:
|
hi @2ynn, class CommunityViewset(LoginRequiredMixin, viewsets.ModelViewSet):
...
def list(self, request, *args, **kwargs):
response = super(CommunityViewset, self).list(request, *args, **kwargs)
if request.accepted_renderer.format == 'json':
return response
# default request format is html:
return Response(
{
'data': response.data,
'filter': get_filter_context(self),
######################!!!!!!!!!!!!!
'new': {
'url': reverse_lazy('person-create'),
'title': _("New Person")
}
}
) To enable the html filtering in DRF browsable api, I have to return only the serializer output:
|
@mina-andajos have you looked into the |
for example you could do something like this:
And the 'new' field would be added only once, not for all objects This is nice when you have nested serializers (with many=True) but it might not be what you are looking for in the case of a list view. Instead you can pass additional context to the Viewset using
https://stackoverflow.com/questions/39202380/django-rest-framework-how-to-add-context-to-a-viewset |
hi @2ynn , 1- I tried the [
{
"id": 3,
"person": {
"actor_id": 4,
"name": "Mina Andajos",
...
"new": {
"url": "/person/create/",
"title": "New Person"
}
},
{
"id": 2,
"person": {
#!!!!! another new below 2- I also found that the JSON list response of the serializer doesn't work with the HTML templates as they expect a dict. 3- I followed the stackoverflow link you provided as well but I'm still facing the same error above. I'm thinking of this method to fix these problems:
What do you think? |
Type of Issue:
Code refactor
Steps to Reproduce:
Expected Behavior:
Current Behavior:
get_filter_context()
and'new'
which could be reversed.Code Snippets:
HarvestViewset.list()
context (without serializer output):Related URLs:
https://localhost:8000/harvest/
And the rest of the list views.
The text was updated successfully, but these errors were encountered: