#26100: Queryset.extra use case: iregex against regular expressions stored as
fields
----------------------------------------------+----------------------------
Reporter: jeffcjohnson | Owner: nobody
Type: Uncategorized | Status: new
Component: Database layer (models, ORM) | Version: 1.9
Severity: Normal | Keywords: Queryset.extra
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+----------------------------
As requested, here is an example of something I couldn't figure out how to
do without using Queryset.extra().
Given an email address, find all regular expressions from the database
that match the email address. It would be like doing iregex in reverse.
{{{
class EmailFilter(models.Model):
regex = models.CharField(blank=False, max_length=128, db_index=True,
help_text="Do not send to email addresses that match this regular
expression. Not case sensitive. E.g.: ^admin@.*$")
@classmethod
def find_matching_rules(cls, email):
return cls.objects.extra(where=['%s ~* regex'], params=[email])
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26100>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" 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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.e0e6f5abb3c364ebcbb2f61a64110885%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.