Django1.6:按boolean和likes排序对象

2024-10-02 02:28:06 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个医生模型,在这个模型中我根据最高的喜好显示医生对象。我对每个医生都有一个布尔值字段,不管该医生是否有赞助。我想先展示赞助的医生,然后他们的其他人应该根据最高的喜好排序。在

下面是我要按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)

我最喜欢的医生是什么?在


Tags: 模型truedefaultmodelsgendernulllengthmax

热门问题