Calculate occurences of phrase in Text Field Django

How can I filter my model MyModel on the basis of the number of occurences of a certain phrase in a text field in MyModel

I guess it can't be done with django orm, perhaps an SQL query can help?

Something like:

MyModal.objects.extra(count="SQL query that finds occurence count of a certain phrase in certain model field")

A complete raw query is fine too.


try this:

set @str='a b a c';
select length(@str)-length(replace(@str,'a','')) as 'number of occuarence'

Need Your Help

“ORA-00913: too many values” error when I run SQL query

sql oracle oracle11g ora-00913

I'm getting a "too many values" error and I'm not sure how to approach it. The problem starts at the first nested SELECT

Erlang and SOAP services - A rock and a hard place

web-services soap erlang mnesia yaws

My question may first of all seem to have a duplicate but i have hit something that has suprised me. Yaws Webserver comes with a complete set SOAP example, but when i tried running it as is, this i...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.