ManyToMany Relationshipを使用してクエリを実行しようとしています。これはこれまでのところです。
designs = designs.filter(Q(title__icontains = search) |
Q(tags__icontains = search))
クエリで tags.title フィールドを検索する方法を知っていますか?
ここにモデルがあります。私はそれらをクリーンアップしたので、それほど長くはありません:)
class Design(models.Model):
title = models.CharField(max_length = 50, default = "")
slug = models.SlugField(unique = True)
user = models.ForeignKey(User, related_name = "design_user")
description = models.TextField()
tags = models.ManyToManyField(to = Tags)
class Tags(models.Model):
title = models.CharField(max_length = 50, unique = True)
# Allows the category to list as a dropdown in the admin
def __unicode__(self):
return self.title
私が調べた質問のほとんどはフィルターを使用しており、私は Django のマスターではないので、重複した質問を追加しないことを願っています。