Python Django 1.6:按布尔值和类似值对对象排序
我有一个医生模型,我在其中显示基于最高喜好的医生对象。我为每个医生都有一个布尔字段,无论该医生是否有赞助。我想先向受资助的医生展示一下,然后再根据最喜欢的医生对他们进行分类 下面是我要按netlikes排序的内容,它正在运行Python Django 1.6:按布尔值和类似值对对象排序,python,django,sorting,Python,Django,Sorting,我有一个医生模型,我在其中显示基于最高喜好的医生对象。我为每个医生都有一个布尔字段,无论该医生是否有赞助。我想先向受资助的医生展示一下,然后再根据最喜欢的医生对他们进行分类 下面是我要按netlikes排序的内容,它正在运行 doctors = Doctor.objects.all().order_by('-netlikes') 我试过了,但没什么不同 doctors = Doctor.objects.all().order_by('sponsored').order_by('-netlike
doctors = Doctor.objects.all().order_by('-netlikes')
我试过了,但没什么不同
doctors = Doctor.objects.all().order_by('sponsored').order_by('-netlikes')
医生模型.py
class Doctor(models.Model):
name = models.CharField(max_length=1300)
title = models.CharField(max_length=1300, null = True, blank = True)
specialization = models.ForeignKey(Specialization)
clinic = models.ForeignKey(Clinic)
education1 = models.CharField(max_length=1300)
gender_choices = ( ('Male', 'Male'), ('Female','Female'),)
gender = models.CharField(max_length=15, choices = gender_choices, null=True, blank = True)
image = models.ImageField(upload_to='uploads/', null=True, blank = True)
likes = models.IntegerField(default=0)
dislikes = models.IntegerField(default=0)
netlikes = models.IntegerField(default=0)
submitted_on = models.DateTimeField(auto_now_add=True, null = True, blank = True)
sponsored = models.BooleanField(default = False)
你知道我如何先向受赞助的医生展示,然后再向他们展示最受欢迎的医生吗?在django中,你不能通过链接
医嘱,最后一个医嘱会覆盖所有之前的医嘱。要避免它,只需使用
doctors = Doctor.objects.all().order_by('sponsored', '-netlikes')