I'm trying to order a query set by a property I defined in the model, but not sure the best way to do this. Here's the property:
@property
def name(self):
if self.custom_name:
return self.custom_name
else:
return self.module_object.name
Essentially, I'd like to do a:
things = Thing.objects.all().order_by('-name')
but of course getting a Caught FieldError while rendering: Cannot resolve keyword 'name' into field.
Any ideas?
EDIT: I understand that I can't sort this way because the @property
isn't a database field. My question is how to sort given that @property
isn't a database field.