I'm wondering if maybe get should raise an error with a name like
"MultipleValueError" rather than "AssertionError" when multiple values
are found...
Yesterday I was wiring up a toggle method. If the row is in the
database, remove it. If it isn't in the database, add it.
I don't have the exact code in front of me but it was something like
this:
def mytoggle(var):
try:
setting = Setting.objects.get(var=var)
setting.delete()
except DoesNotExist:
setting.objects.create_setting(var=var).save()
except AssertionError:
setting.objects.filter(var=var).delete()
The check for AssertionError is a "just in case" check that somehow
the variable slipped in there twice. But I'm wary of attaching code
to an assertion error.
I don't have a lot of Python experience so maybe that's reasonable.
Thanks,
Rob