[Answered ]-Grouping django objects using QuerySet API by shared text tags using two models with ForeignKey relationship


You’d better create two additional models: one for Tag and one for link between Tag and Document. If it’s somewhy unacceptable, you can use something like:

Document.objects.filter(tagdb__tag_text__in=doc.tags_as_csv.split(' , ')).distinct()

Plus, add model method for getting/setting tags, it will ease any possible refactoring.


Leave a comment