IndexError 'list index out of range' in Django Admin

· 82 Words

Have you just got an exception from Django saying:

IndexError at /admin/mything/

list index out of range

With a stack trace ending in :

.../django/db/models/ in __getitem__

190. return self._result_cache[k]

I just did. Two bug reports looked hopeful but didn’t fit the bill. Then I remembered that I was overriding save in my ModelForm.

If you do this:

def save(self, *args, **kwargs):
   obj = super(DataOfferingForm, self).save(*args, **kwargs)

Remember to do this:

  return obj

The super’s return value needs to be returned!

Read more