Hi,

There is no way to do that in a pure Django ORM, so only option is to fall
back to raw SQL. The exact SQL syntax is dependent on your database backend
but Django can still get you real model instances. See more about raw SQL
at https://docs.djangoproject.com/en/dev/topics/db/sql/

Though if you're pulling all results in your code you can easily add pure
Python property/method to your model to get count of the keyword and then
it would be database agnostic.

On Wed, May 9, 2012 at 6:30 PM, Guillaume Florent
<florentsail...@gmail.com>wrote:

> Hi everybody,
> I would like to know if there if a simple way to know how many times a
> given field contains a string.
> e.g. Note.objects.filter(notedescription__contains='keyword')
> What would be the recommended way to know how many times 'keyword' is
> hit in the 'notedescriptiont' field? Do I have have to iterate over
> the resulting queryset or can someone think of a more elegant way?
> (i.e. is adding on the fly a 'count' field to each object in the
> queryset feasible?)
> Best regards,
> G Florent
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>
>


-- 
Jani Tiainen

- Well planned is half done, and a half done has been sufficient before...

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to