django-rest-viewsets

Use serializer of model having foreign key to do CRUD on parent table in Django Rest Framework

落花浮王杯 提交于 2019-12-06 11:32:28
In my API, I have two models Question and Option as shown below class Question(models.Model): body = models.TextField() class Options(models.Model): question = models.ForeignKey(Question, on_delete=models.CASCADE) option = models.CharField(max_length=100) is_correct = models.SmallIntegerField() While creating a question it would be nicer the options can be created at the same time. And already existed question should not be created but the options can be changed if the options are different from previous. I am using ModelSerializer and ModelViewSet . I use different urls and views for Question

Django-filters does not work with the Viewset

放肆的年华 提交于 2019-12-02 03:12:24
I have been trying to use django-filters but the objects are not getting filtered. Also, the permission is not working for the partial_update views I have a Viewset which has the basic actions like - list(), retrieve(), destroy(), partial_update() and few other actions, and trying to apply filter for the same. After some research I found that since I am creating the queryset via filters I will have to override the get_queryset() method. However, that also doesn't seem to be working. Does the filter works only with ModelViewSet or ListApiView ? ViewSet - class PostViewSet(viewsets.ViewSet): """

Django-filters does not work with the Viewset

我的梦境 提交于 2019-12-02 01:36:16
问题 I have been trying to use django-filters but the objects are not getting filtered. Also, the permission is not working for the partial_update views I have a Viewset which has the basic actions like - list(), retrieve(), destroy(), partial_update() and few other actions, and trying to apply filter for the same. After some research I found that since I am creating the queryset via filters I will have to override the get_queryset() method. However, that also doesn't seem to be working. Does the