Given a class:
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=20)
Is it possible (and if so how) to have a QuerySet that filters based on dynamic arguments, likeso:
# instead of
Person.objects.filter(name__startswith='B')
# and
Person.objects.filter(name__endswith='B')
# is there some way, given:
filter_by = '%s__%s' % ('name', 'startswith')
filter_value = 'B'
# You can run the equiv. of
Person.objects.filter(filter_by=filter_value)
# which throws an exception
Help is much appreciated & thank you in advance.