Any help on this one would great. I'm using python 2.7 and django 1.2 Here's my code:
for save in saved: #list to iterate
try:
sect = obj.get(name=save) #obj is a RelatedManager
except: #if two sections have the same name
sect = obj.filter(name=save)
else:
#finish my code
I get a MultipleObjectsReturned error everytime when it hits the get() statement. I'm no expert at python so I imagine I missed something simple.
Two objects have the name values equal to the value of save
When using get and there are more than 1 row returned it raises MultipleObjectsReturned
I think you should catch this explicitly because your except as it stands will also catch DoesNotExist errors (and all oteher errors)
from django.core.exceptions import MultipleObjectsReturned
try:
sect = obj.get(name=save) #obj is a RelatedManager
except MultipleObjectsReturned: #if two sections have the same name
sect = obj.filter(name=save)[0]
else:
#finish my code
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With