Opened 12 years ago
Closed 12 years ago
#20374 closed Bug (invalid)
When saving a form in Admin with an Inline, I get 'not subscriptable' error
| Reported by: | 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 |
Description
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
admin.py:
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, ]
models.py:
class GlobalLanguages(models.Model):
lang_id = models.CharField(max_length=2,
primary_key=True,
verbose_name=_('Language ID'),
help_text=_('ISO 639-1 2 letter language code - see: <a href="http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes" target=_blank>http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes</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,
verbose_name=_('Active'),
db_column='is_active')
created = models.DateTimeField(auto_now_add=True,
editable=False)
modified = models.DateTimeField(auto_now=True,
editable=False)
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,
primary_key=True,
verbose_name=_('Country Code'))
primary_lang_id = models.ForeignKey(GlobalLanguages)
active = models.BooleanField(default=True,
verbose_name=_('Active'),
db_column='is_active')
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,
lang_id=cur_lang)
if countryname is None:
countryname = GlobalCountriesNames.objects.get(country_id=self.countrycode,
lang_id='en')
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,
verbose_name=_('Country'))
lang_id = models.ForeignKey(GlobalLanguages,
verbose_name=_('Language'))
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')
Note:
See TracTickets
for help on using tickets.
Hi,
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
LogEntryobject corresponding to the creation of your model.The error message indicates that your model's
__unicode__method returned an instance ofMyModelNamerather 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:Thanks.