Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Q' object has no attribute 'split' - Django

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.

like image 497
doniyor Avatar asked Apr 03 '14 17:04

doniyor


1 Answers

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')
like image 189
Sohan Jain Avatar answered Nov 15 '22 06:11

Sohan Jain