0

I using Q object as for search,

tracks_list = Track.objects.order_by("rating")
query = request.GET.get("search")

if query:
    tracks_list = tracks_list.filter(
            Q(title__icontains(query))|
            Q(genres__name__icontains(query))
    ).distinct()

and my models are described as,

class Track(models.Model):

  title = models.CharField(max_length=128)
  genres = SortedManyToManyField(Genre)
  rating = models.IntegerField(default=0, validators=[MaxValueValidator(10), MinValueValidator(0)])

class Genre(models.Model):
  name = models.CharField(max_length=128, unique=True, null='False')
  views = models.IntegerField(default=0)
  slug = models.SlugField(unique=True)

Yet I am receiving a NameError stating global name 'title__icontains' is not defined

1 Answer 1

3

you need

title__icontains=query

instead of

title__icontains(query)

the same applies for genres__name__icontains

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.