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 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 yet
>      except ObjectDoesNotExist:
>          [[[Make the object, etc]]]
>
>
> 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.
>
> Thanks,
> Tyson
>
> -- 
> Tyson Tate
> - CalPoly Graphic Design Student
> - Work: Graphic Designer (CalPoly Library)
> - Play: Mustang Band, CalPoly Triathlon Team, Kappa Kappa Psi (Iota  
> Pi)
>
> >


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to