SearchableText.objects.filter(searchterm__term__in=('is', 'another')).order_by('searchterm__term')
is this what you need?
On Sat, Oct 29, 2016 at 7:03 PM, Yaşar Arabacı <yasar11732@gmail.com> wrote:
Hi,--I am trying to migrate my mysql application into django orm. I need help converting my sql statements into it. Here are my modelsclass SearchableText(models.Model): searchable_text = models.TextField() class SearchTerm(models.Model): searchabletext = models.ForeignKey(SearchableTe
xt , 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 thisSearchableTextid searchable_text1 "this is text"2 "this is another text"SearchTermid searchable_text term1 1 this2 1 is3 1 text4 2 this5 2 is6 2 another7 2 textI would normally do a sql query like this;Select SearchableText.*Right Join SearchTerm on SearchTerm.searchable_text = SearchableText.idWhere term in ("is","another")group by SearchTerm.searchable_text ORDER BY COUNT(SearchTerm.term ) DESC LIMITRight now, I don't even know where to start writing a complex sql like this using django-orm so any help is appreciated.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com .
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users .
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c6481fa3- .1d35-4957-b70e-3d9912715546% 40googlegroups.com
For more options, visit https://groups.google.com/d/optout .
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFWa6tLyTgXJz%2BuYYooAZi0okdG5%2BZ211L9DSk5_S9DA3T87zw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment