models.py
from django.db import models
from collections import Counter
from django.db.models import Count
from itertools import groupby
Gender = (
('Male', 'MALE'),
('Female', 'FEMALE'),
)
Diseases = (
('Cholera', 'CHOLERA'),
('HIV', 'HIV'),
('Malaria', 'MALARIA'),
('Typhoid', 'TYPHOID'),
('Measles', 'MEASLES'),
)
class MyModel(models.Model):
Gender = models.CharField(max_length=16, choices=Gender, default='MALE')
Diseases = models.CharField(max_length=16, choices=Diseases, default='MALARIA')
vote = models.IntegerField(default=0)
def __str__(self):
r=0
return u'%s %s' % (self.Gender, self.Diseases)
现在,这将在管理Django面板中返回
Male Measles
Male Measles
Male Cholera
Female Cholera
Female Typhoid
Female Typhoid
但是我想对其进行分组,使其看起来像这样:
Male malaria 2
Male Measles 2
Female Typhoid 3
在此管理面板中,而不是像现在一样列出所有内容