On Thursday, 9 February 2012 13:41:31 UTC, anand jeyahar wrote: > > > Hi > > > > >> There's no searching going on here. You create a lock instance, >> passing two positional arguments, which Django interprets as the first >> fields, ID and name. >> >> That's why you should never use positional arguments when instantiating - >> always do it via keyword arguments: >> lock = Lock(name=name, info=info) >> >> Thanks a lot Daniel.. i feel dumb now.. > > >> Note that as I say, you're not actually checking if there's a lock with >> that name already. You probably want to actually do that. >> > > Hmm.. i was just happy to leave it to the db to raise an error. since i > use the unique key, that should work.. > I agree should put in a check for the type of exception and display the > right message though... > >> >> You can use `get_or_create` to do this check for you: https://docs.djangoproject.com/en/1.3/ref/models/querysets/#get-or-create -- DR.
-- You received this message because you are subscribed to the Google Groups "Django users" group. To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/nJUAQrvLGVgJ. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.