Tyson Tate wrote:
> However, raising an exception on "success" irks the part of me that
> studied computer science for 3 years, so I'm wondering if anyone
> knows of any other ways I might be able to achieve the above in a
> better way.
Compared to other languages, exception in python are
You could just check the count of that many items (since its unique it
should always be 1 or 0):
if Photo.objects.filter(flickr_id=photo("id")).count() == 0:
# create the object ...
But its my understanding that Python exceptions are not as heavy weight
as they are in languages like
http://www.djangoproject.com/documentation/models/get_or_create/
?
but yeah.. besides from using get_or_create, the exception route is
probably the easiest route.
On 27/06/2006, at 4:58 PM, Tyson Tate wrote:
>
> In one of my apps, I need to check and see if a row already exists
> based on a
In one of my apps, I need to check and see if a row already exists
based on a unique field. Currently, I'm doing something like the
following:
for photo in photos:
try:
row = Photo.objects.get(flickr_id=photo("id"))
# Raise exception if photo doesn't exist in our DB
4 matches
Mail list logo