I have a model called Book with a Title Field.
class Book(models.Model):
title = models.CharField(null = False,blank=False)
Now I need a filter to get all books with titles starting with a number.
This works but how will I extend the queryset?
b = Book.objects.filter(title__startswith = 1).order_by('title')
This doesn’t work
b = b + Book.objects.filter(title__startswith = 2).order_by('title')
or this
b.extend(Book.objects.filter(title__startswith = 2).order_by('title'))
You can use a regular expression as a query parameter to check that the a value starts with a number: