Django api calculate count of responses -


I'm trying to apply a survey in the Django. My model is as follows:

  class mymodel (models.model): restype = models.ForeignKey (answer) ques = models.ForeignKey (question) feedback = models.CharField (max_length = 5, empty = True)  

Here I am using the rest frame to send data to my front end. I now have my API Defined:

  class mymodelList (APIView): def find (auto, request, format = none): surveydata = mymodel.objects. () Serialized_surveydata = mymodel Serializer (SurveyData, many = True) Returns (serialized_surveydata.data)  

In my app, I have a standard set of 16 questions with many selected responses in the choice model The response is saved in the column.

Now, what I am trying to achieve is counting the count of responses for each question. To wit. For Question 1, a person has responded with 1 or 2 or etc.

In addition to this, I want to know how to calculate the calculation through the rest of the structure through another Jason field because I do not have any separate model for this data.

Edit:

This command did the trick for my query, but I still can not understand how to send it to the front end as a serialized object is.

ex> x = mymodel.objects.values ​​('ques', 'feedback'). Order_by (). Annotate (number_of_responses = count ('response'))

There is not a great structure, maybe it will be easy to create separate questions and choice classes. Actually uses this type of application as an example ... Take a look at it for some guidance


Comments