Good afternoon, the following problem arose: there is a model that stores images for the gallery.
class Gallery(models.Model): image = models.FileField(upload_to='gallery/') status = models.BooleanField() type = models.BooleanField() On the page this model is used to display as a gallery in the form of a tile, masonry. The tile is fixed and the problem is that you need to take 12 random pictures, it is easy.
gallery = Gallery.objects.all().order_by('id','pk').order_by('?')[: 12]; But so that 5 of them have the type True, and the other 7 False. And if it is still possible to customize the order it would be generally perfect, well, let's assume that we have True - the picture is horizontal (d), and False is vertical (c). I would like to make a sample in which there will be, for example, such an order [c, d, d, d, c, c, c, d, d, c, c, c]