I was wondering if it could be possible to query a Django model using aliases of its fields?
for exemple:
class Book(models.Model):
pub_date = models.DateTimeField(_('Publication Date'),
...
class Magazine(models.Model):
creation_date = models.DateTimeField(_('Publication Date'),
...
I can alias the class, which is great:
my_class = Book
then query it as:
my_class.objects.all()
Fine!
I would like to be able to alias the Book.pub_date & Magazine.creation_date as my_pub_date, so I could do:
Book.objects.filter(my_pub_date__gt=some_date) (or my_class.objects.filter(my_pub_date__gt=some_date))
instead of:
Book.objects.filter(pub_date__gt=some_date)
Thanks
Book.get_published_after_querysetclassmethod? You could do similar methods onMagazine, etc, and then just callmy_class.get_pushed_after_queryset(some_date).filter(...).