It might be easier to write a manager depending on what exactly you're
trying to do. In my opinion you should write an operator for a
database feature that you're trying to implement but if you're trying
to cleanup text or transform text in some way... I think a manager
might be a better solution.

If the problem involves converting the text to the left side of the
equal sign (the table column).. then I would be careful you don't get
table scans all over the place.

On May 4, 5:26 am, pbzRPA <[email protected]> wrote:
> I would like to know if anyone knows how to create custom operators
> for querysets.
>
> Currently you can do something like:
>
> foo.objects.filter(myfield__icontains = x)
>
> I would like to add my own operator so I can do something like:
>
> foo.objects.filter(myfield__converttext = x)
>
> where "converttext" would be my own operator. Currently there a few
> operators in the django/db/backends/mysql/base.py:
>
> operators = {
>         'exact': '= %s',
>         'iexact': 'LIKE %s',
>         'contains': 'LIKE BINARY %s',
>         'icontains': 'LIKE %s',
>         'regex': 'REGEXP BINARY %s',
>         'iregex': 'REGEXP %s',
>         'gt': '> %s',
>         'gte': '>= %s',
>         'lt': '< %s',
>         'lte': '<= %s',
>         'startswith': 'LIKE BINARY %s',
>         'endswith': 'LIKE BINARY %s',
>         'istartswith': 'LIKE %s',
>         'iendswith': 'LIKE %s',
>     }
>
> I would like to add to this dict without modifying the django code.
>
> Any help would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to