我在 Django 中有这样的模型:
class Session(models.Model):
user = models.ForeignKey(User)
session_name = models.CharField(max_length=254)
server_full_path = models.CharField(max_length=254) # Contains server
server_name = models.CharField(max_length=254) #Server Name or IP
file_path = models.CharField(max_length=254) #full file path
source_username = models.CharField(max_length=100)
source_password = models.CharField(max_length=100)
make_default = models.BooleanField()
我正在使用此查询来获取所有 server_id:
all_server_id = Session.objects.filter(user_id=request.user.id)
我希望对查询进行排序,使 make_default=1 的值首先出现。我希望它显示在模板中。我怎样才能做到这一点?