Django group by in many to many relationships -


मेरे पास निम्न स्कीमा के साथ मूल्यांकन नाम का एक मॉडल है:

  user = models.ForeignKey ( उपयोगकर्ता) मूल्य = models.IntegerField ()  

मूल्य क्षेत्र 0,1,2,3 में मान ले जाएगा।

अब मैं की गिनती प्राप्त करना चाहते हैं प्रत्येक मान के साथ दिए गए उपयोगकर्ता के मूल्यांकन उदाहरण के लिए, मान लें कि मेरे डेटा हैं:

  user.id | मूल्य 1 | 0 1 | 0 1 | 1 1 | 2 1 | 3 1 | 3  

मुझे परिणाम प्राप्त करना है

  मूल्य | गिनती 0 | 2 1 | 1 2 | 1 3 | 2  

मैं क्वेरी का उपयोग

  Evaluation.objects.filter (user = request.user)। एनोटेट (गणना = गणना ('मान')) .order_by ('value')  

लेकिन यह सही उत्तर नहीं लौटाता है। कोई भी मदद कर सकता है?

आप ऐसा कर सकते हैं:

  मूल्यांकन (संख्या = 'मान'))। आदेश ('मान')  

Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -