W dniu 26.01.2009 13:08, Stefan Tunsch pisze:
> Hi!
>
> I have a qset object like this:
>
> qset = (
> Q(dst__contains=company.phone) |
> Q(dst__contains=company.cellphone) |
> Q(dst__contains=company.fax) |
> Q(src__contains=company.phone) |
> Q(src__contains=company.cellphone) |
> Q(src__contains=company.fax)
> )
>
> If a company has a None value in one of these fields, I get a "Cannot
> use None as a query value" error.
>
> I would want to add Q objects dynamically depending on the situation. Is
> this possible?
>
> Regards, Stefan
>
Hi, you can do this:
qobj=None
if company.phone:
if qobj:
qobj = qobj | Q(dst__contains=company.phone)
else:
qobj=Q(dst__contains=company.phone)
if company.cellphone:
if qobj:
qobj = qobj | Q(dst__contains=company.cellphone)
else:
qobj=Q(dst__contains=company.cellphone)
etc...
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---