Opened 3 years ago

Closed 3 years ago

#20374 closed Bug (invalid)

When saving a form in Admin with an Inline, I get 'not subscriptable' error

Reported by: evlsin@… Owned by: nobody
Component: contrib.admin Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


When I try to save in the admin, I get:

TypeError: 'MyModelName' object is not subscriptable

affected line is: e = self.model(None, None, user_id, content_type_id, smart_text(object_id), object_repr[:200], action_flag, change_message)

I dropped back down to Django 1.4.5 and the form works just fine now

class CountryNameInline(admin.TabularInline):
    model = GlobalCountriesNames
    extra = 1

class CountryAdmin(admin.ModelAdmin):
    list_display = ('countrycode', 'country_name', 'primary_lang_id', 'active')
    list_display_links = ('countrycode', 'country_name')
    inlines = [CountryNameInline, ]

class GlobalLanguages(models.Model):
    lang_id = models.CharField(max_length=2,
                               verbose_name=_('Language ID'),
                               help_text=_('ISO 639-1 2 letter language code - see: <a href="" target=_blank></a>'))
    lang_name = models.CharField(max_length=30,
                                 verbose_name=_('Language Name'),
                                 help_text=_('Use the language name in it\'s native language'))
    active = models.BooleanField(default=True,
    created = models.DateTimeField(auto_now_add=True,
    modified = models.DateTimeField(auto_now=True,

    def __unicode__(self):
        return self.lang_name

    class Meta:
        verbose_name = _('Language')
        verbose_name_plural = _('Languages')
        permissions = (('can_add_edit_languages', _('Can Add or Edit Languages')))

class GlobalCountries(models.Model):
    countrycode = models.CharField(max_length=2,
                                   verbose_name=_('Country Code'))
    primary_lang_id = models.ForeignKey(GlobalLanguages)
    active = models.BooleanField(default=True,
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

    class Meta:
        verbose_name = _('Country')
        verbose_name_plural = _('Countries')
        permissions = (('can_add_edit_countries', _('Can Add or Edit Countries')))

    def _get_country_name(self):
        cur_lang = get_language()
        countryname = GlobalCountriesNames.objects.get(country_id=self.countrycode,
        if countryname is None:
            countryname = GlobalCountriesNames.objects.get(country_id=self.countrycode,
        return unicode(countryname)

    country_name = property(_get_country_name)

    def __unicode__(self):
        return self.country_name

class GlobalCountriesNames(models.Model):
    country_id = models.ForeignKey(GlobalCountries,
    lang_id = models.ForeignKey(GlobalLanguages,
    country_name = models.CharField(max_length=120,
                                   verbose_name=_('Country Name'))
    created = models.DateTimeField(auto_now_add=True)
    modified = models.DateTimeField(auto_now=True)

    def __unicode__(self):
        return self.country_name

    class Meta:
        verbose_name = _('Country Name')
        verbose_name_plural = _('Country Names')
        unique_together = ('country_id', 'lang_id')

Change History (1)

comment:1 Changed 3 years ago by bmispelon

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to invalid
  • Status changed from new to closed


I cannot reproduce your issue (I tried with both version 1.5 and the latest one).

The problem you describe seems to arrise when creating a LogEntry object corresponding to the creation of your model.
The error message indicates that your model's __unicode__ method returned an instance of MyModelName rather than the expected unicode string, which is not consistent with the code you pasted.

In consequence, I'm marking this issue as invalid. Please re-open it and provide:

  • The full error traceback
  • The actual code that triggers the error (the more you can simplify this code, the easier it is for someone to review this ticket)


Note: See TracTickets for help on using tickets.
Back to Top