How to order a queryset based on the multiselectfield values

Viewed 16
choix = (

('Proche station ski','Proche station ski'),
('Piscine', 'Piscine'),
('Jardin', 'Jardin'),
('Cave', 'Cave'),
('Parking', 'Parking'),

)

class Appartement(models.Model): surface = models.FloatField() prix = modelsenter code here.FloatField() nombre_piece = models.IntegerField()

list_caracteristiques = MultiSelectField(choices=choix, max_length = 200)
program = models.ForeignKey(Programme_immobilier, on_delete=models.CASCADE)

def __str__(self) -> str:
    return f"Appartement {self.id} de {self.program_id}"

My task is to do the following:

List the apartments by ordering the answer according to the season (according to the date of the request) as follows: o In winter (December – March) the apartments that are "Proche station ski" appear first, then sort by decreasing price, decreasing area, o In summer (June – September) the apartments with a "Piscine" appear first, then sort by decreasing price, decreasing area. Otherwise, sorting is by decreasing price, decreasing area

I am stuck at how to sort the queryset, based on the values of the multiselectfield

Thanks in advance for any cooperation !

0 Answers
Related