hi Yasar,
create_dic_of_searchterm = {'searchabletext_id':1,'term':'this'}
SearchTerm.objects.create(**create_dic_of_searchterm)
you can do like above
On Sat, Oct 29, 2016 at 9:33 PM, Yaşar Arabacı <[email protected]> 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 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.
>
> --
> 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 [email protected].
> To post to this group, send email to [email protected].
> 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
> <https://groups.google.com/d/msgid/django-users/c6481fa3-1d35-4957-b70e-3d9912715546%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
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/CAGGVXBOcXH_nrg_oGUnjdUU4Xy%3DipJOXSjZ9xxoUkXm0HNBJTA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.