Question

I have a Model:

class Authors(models.Model):
   name = models.TextField()
   person = models.ForeignKey(Person)

and query:

authors = Author.objects.filter(
                                (Q(name__iregex=r"\y{0}\y".format(s1)),
                                ~Q(name__iregex=r"\y{0}\y".format(s2))
                                ),
                                person=None).order_by('-id')

I am getting the error:

'Q' object has no attribute 'split'

why is this? i am not using split() though.. the line of error is in this query line.

Was it helpful?

Solution

I think you need to join your Q() filters with a logical operator like | or &.

authors = Author.objects.filter(
                                (Q(name__iregex=r"\y{0}\y".format(s1)) &
                                ~Q(name__iregex=r"\y{0}\y".format(s2))
                                ),
                                person=None).order_by('-id')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top