我有一个医生模型,在这个模型中我根据最高的喜好显示医生对象。我对每个医生都有一个布尔值字段,不管该医生是否有赞助。我想先展示赞助的医生,然后他们的其他人应该根据最高的喜好排序。在
下面是我要按netlikes分类的方法,它很管用
doctors = Doctor.objects.all().order_by('-netlikes')
我试过了,但没什么不同
^{pr2}$医生模型.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中链接
order_by
,最后一个会覆盖之前的所有顺序。为了避免它,只要使用相关问题 更多 >
编程相关推荐