NestedViewSetMixin suport for saving
See original GitHub issueIs looks like using the NestedViewSetMixin
auto generates the filter code for nested routers, but does nothing for saving.
I would recommend something like the following for a URL like companies/company_pk/locations/location_pk
:
def pre_save(self, obj):
obj.location = Location.objects.get(pk=self.kwargs['location_slug'],
company__pk=self.kwargs['company_pk']
)
to be auto generated so that a user posting to the above URL can omit those fields which are determined by the URL itself.
Issue Analytics
- State:
- Created 9 years ago
- Comments:24 (9 by maintainers)
Top Results From Across the Web
Django Rest Framework extensions documentation
class TaskViewSet(NestedViewSetMixin, ModelViewSet): model = TaskModel class ... Django's save method has keyword argument update_fields.
Read more >Django REST Framework extensions - DRF - pointborn
Extensions for serializers functionality. PartialUpdateSerializerMixin. By default every saving of ModelSerializer saves the whole object. Even ...
Read more >alanjds/drf-nested-routers - Gitter
Hi @jogilder. Glad that you worked this out. I was starting to bisect thru the release versions to see which one stopped to...
Read more >Django-filter Choice Filter does not recognize an existing field ...
class StartUpViewSet(NestedViewSetMixin, ModelViewSet): ... Field does not exist · Django - Which file types does Django's image field support / not support ......
Read more >The Ultimate Tutorial For Django Rest Framework - Sunscrapers
views.py class BorrowedViewset(NestedViewSetMixin, viewsets. ... only for reading and adding, the saving option will require more work.
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
@chibisov I don’t know if there is a way to find the model from a related field, but I suppose yes.
You should add
create
andupdate
override inNestedViewSetMixin
.I have copied rest_framework implementation of create then I added related datas from parents_query_dict to a new dict and used it in get_serializer instead the base request.data
Edit another way to do this is move all to the serializer create and update
Hi! Why not simple call the
self.get_parents_query_dict()
for getting all url values?Edit I’m overriding the base write requests for getting that work. Maybe my work can be included into the extensions to insert automatically url datas in request.data