I have model that I need to be able to order in the admin panel alphabetically by the title of the image foreign key. Currently with the code below the models get ordered by when the associated 'logo' images were added to the database, as opposed to by the titles of the associated 'logo' images.
class Client(models.Model):
logo = models.ForeignKey(
'wagtailimages.Image',
null=True,
blank=True,
on_delete=models.SET_NULL,
related_name='+',
)
homepage_visible = models.BooleanField(default=True)
panels = [
MultiFieldPanel([
ImageChooserPanel('logo'),
FieldPanel('homepage_visible'),
], heading='Client information'),
]
def __str__(self):
return self.logo.title
class Meta:
verbose_name = 'Client Logo'
verbose_name_plural = 'Client Logos'
ordering = ['logo']