0

Hello i have a wallpaper website. Im using taggit. I have 200k tags and have 20k wallpaper.

I want use related wallpapers in view like this

def detail(request,slug):

    wallpaper = get_object_or_404(Wallpapers, slug = slug)
    category = Category.objects.all()
    similar_posts = wallpaper.tags.similar_objects()[:20]
    random.shuffle(similar_posts)
    return render(request, "detail.html", {"wallpaper": wallpaper, "category": category, "similar_posts": similar_posts,  })

and i take "too many SQL variables" error.

example wallpaper tags: anime, water, rain

15k+ wallpaper have anime tag

How can i limit or filter query this related wallpaper items?

Aytek
  • 224
  • 4
  • 16

1 Answers1

1

I FOUND SOLUTION LIKE THIS

 similar_posts = wallpaper.tags.similar_objects()[:20]
 random.shuffle(similar_posts)

change to;

 similar_posts = Wallpapers.objects.filter(tags__name__in = [wallpaper.tags.names()]).order_by('?')[:20]
Aytek
  • 224
  • 4
  • 16