Hi,
I am trying to migrate my mysql application into django orm. I need help converting my sql statements into it. Here are my models
class SearchableText(models.Model):
searchable_text = models.TextField()
class SearchTerm(models.Model):
searchabletext = models.ForeignKey(SearchableText, on_delete=models.CASCADE)
term = models.CharField(max_length=100)
This is basically a table to store some textual information, and another table to use as index of searchable terms.
Consider it like this
SearchableText
id searchable_text
1 "this is text"
2 "this is another text"
SearchTerm
id searchable_text term
1 1 this
2 1 is
3 1 text
4 2 this
5 2 is
6 2 another
7 2 text
I would normally do a sql query like this;
Select SearchableText.*
Right Join SearchTerm on SearchTerm.searchable_text = SearchableText.id
Where term in ("is","another")
group by SearchTerm.searchable_text ORDER BY COUNT(SearchTerm.term ) DESC LIMIT
Right now, I don't even know where to start writing a complex sql like this using django-orm so any help is appreciated.