Thanks that works well, but when I try to use the ~ as you suggested I get the error ""bad operand type for unary ~: 'Q'"" so i removed the ~ and changed 'filter' to 'exclude'
On Jun 30, 9:53 am, Ayaz Ahmed Khan <[EMAIL PROTECTED]> wrote: > On Jun 30, 7:13 pm, mike171562 <[EMAIL PROTECTED]> wrote: > > > Hello, > > I am working on a django that querys long distance numbers from a > > mysql database. I am currently using the django API, that goes > > something like this. > > > long_distance = > > Call.objects.filter(dest_num__startswith='1').filter(dest_num__gt=6).exclude(dest_num__startswith='18').exclude(dest_num__startswith='1281').exclude(dest_num__startswith='1832').exclude(dest_num__startswith='1713') > > > I was hoping to consolidate all of my .filter excludes into one regex. > > is this possible and would it be more efficient? Basically any number > > that doesnt start with 281,713,832 or 1281,1713,or 1832 is long > > distance any help would be appreciated. > > Using regex mostly complicates things. If I have understood your > requirement properly, the following may be a better and cleaner > alternative: > > from django.models import Q > > long_distance = Call.objects.filter( > > ~Q(dest_num__startswith='281') & > > ~Q(dest_num__startswith='713') & > > ~Q(dest_num__startswith='832') & > > ~Q(dest_num__startswith='1281') & > > ~Q(dest_num__startswith='1713') & > > ~Q(dest_num__startswith='1832 ') > ) > > That is merely an example. You can make up different conditionals > with the use of the Q > feature.http://www.djangoproject.com/documentation/db-api/#complex-lookups-wi... > > -- > Ayaz Ahmed Khan --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---