I made image gallery with grid view, but I don't like the way that rows look like - vertical photos disrupt everything. As I don't want to manually change images order I'm looking for a way to sort them automaticaly by image height or just image orientation, so vertical photos go to the bottom in one row.
Thats how my model in Django looks like:
class Photo(models.Model):
title = models.CharField(max_length=150)
image = models.ImageField()
description = models.TextField(blank=True)
category = models.IntegerField(choices=CATEGORIES)
published = models.DateTimeField(default=timezone.now)
def __str__(self):
return self.title
Here is my grid_view:
def photos_grid(request):
global cat_list
photos = Photo.objects.order_by('published')
output = {'photos': photos, 'categories': cat_list,}
return render(request, 'photos/photos_grid.html', output)
I tried that (how to find height and width of image for FileField Django) way of getting image dimensions but I got
ValueError: invalid literal for int() with base 10: 'height'
every way I try to put it in my code. Other idea (by getting manually dimensions in views.py
) works, but I can't put it together with my photos on the list so it get sorted.