B
B
bituke2021-09-24 17:24:14
Django
bituke, 2021-09-24 17:24:14

How to sort objects by multiple values?

FILM = 0
SERIAL = 1
CARTOON = 2
ANIME = 3
ANIMATED_SERIES=4
TYPE_PICTURE = (
    (FILM, 'Film'),
    (SERIAL, 'Serial'),
    (CARTOON, 'Cartoon'),
    (ANIME, 'Anime'),
    (ANIMATED_SERIES, 'animated-series')
)

class Picture(models.Model):
  ''' модель для картины (фильма, мультфильма, аниме)'''
        type_picture = models.PositiveSmallIntegerField(choices=TYPE_PICTURE, blank=True, null=True)

I want to get all objects that have type_picture = SERIAL and ANIMATED_SERIES (filtering by two values ​​of one field at once) How can I write this?))

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir Kuts, 2021-09-24
@bituke

Picture.objects.filter(type_picture__in=[FILM, SERIAL])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question