List Info

Thread: I get an error when my query returns nothing




I get an error when my query returns nothing
country flaguser name
United States
2007-07-31 11:45:57
Hello,
I have the following if statement in one of my views:
if
(Style.objects.get(id=a.id).sandp.get(price=request['price']
)==True):

//////////////

Sometimes, the query will not find any results.  However,
when this
line gets accessed I get the following error:
Choice matching query does not exist.

///////////////////////////

Does anybody know what i need to do so that I don't receive
this error
when the query returns nothing?

Thanks


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


Re: I get an error when my query returns nothing
country flaguser name
United States
2007-07-31 11:52:24
On 31 jul, 12:45, Greg <gms3...hotmail.com> wrote:
>
> Does anybody know what i need to do so that I don't
receive this error
> when the query returns nothing?
>

  There's a difference with get() and filter(). get() always
returns
an object and it must be use when you're sure you've got
records. In
any other situation you can use filter and then validate
it:

style = Style.objects.filter(id=a.id)
if len(style) > 0:
 """
   There's at least one record.
""


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


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )