﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20753	Beginner confused for MultiValueDictKeyError, where the error comes from?	adam.pahlevi@…	nobody	"I am new to Django and would like to try it for my thesis project. However, I found an error which is MultiValueDictKeyError when I try to save my model from the Django admin.

I have 3 models in this case, which are: BSN (Business), LIN (Lines), ROT (Routes).

BSN:
{{{#!python
class Bsn(models.Model):
    """"""The entity of business""""""

    #the enum for business type
    BUSINESSTYPE = (
        ('bank', 'Bank'),
        ('barclub', 'Bar-Club'),
        ('carrental', 'Car rental'),
        ('church', 'Church'),
        ('clinic', 'Clinic'),
        ('cybercafe', 'Cybercafe'),
        ('exchange', 'Exchange'),
        ('festival', 'Festival'),
        ('fleamarket', 'Fleamarket'),
        ('hotel', 'Hotel'),
        ('mosque', 'Mosque'),
        ('police', 'Police'),
        ('primary', 'Primary'),
        ('restaurant', 'Restaurant'),
        ('secondary', 'Secondary'),
        ('shop', 'Shop'),
        ('sight', 'Sight'),
        ('transportation', 'Transportation'),
        ('uni', 'University')
    )

    bsnid = models.AutoField(primary_key=True)
    id = bsnid.__str__()
    bsnname = models.CharField(""Business name"", max_length=135, unique=True)
    bsntype = models.CharField(""Business type"", max_length=42, choices=BUSINESSTYPE)
    bsndesc = models.CharField(""Description"", max_length=135, blank=True)
    bsnparent = models.ForeignKey('self', null=True, db_column='bsnparent', blank=True)
    bsncoorx = models.DecimalField(""Coordination X in Map"", null=True, blank=True, max_digits=11, decimal_places=0)
    bsncoory = models.DecimalField(""Coordination Y in Map"", null=True, blank=True, max_digits=11, decimal_places=0)
    bsncoorn = models.DecimalField(""Coordination N in Map"", null=True, blank=True, max_digits=11, decimal_places=0)

    def __unicode__(self):
        return self.bsnname

    class Meta:
        db_table = u'bsn'
        verbose_name=""Business""
        verbose_name_plural=""Businesses""
}}}

Class LIN
{{{#!python
class Lin(models.Model):
    """"""model for the line""""""
    linid = models.AutoField(primary_key=True)
    id = str(linid)
    linbsn = models.ForeignKey(Bsn, db_column='linbsnid')

    def __unicode__(self):
        return ""Line "" + self.linbsn.bsnname

    class Meta:
        db_table = u'lin'
        verbose_name = ""Line""
}}}

And, the last but not least, ROT:
{{{#!python
class Rot(models.Model):
    rotid = models.IntegerField(primary_key=True)
    rotlin = models.ForeignKey(Lin, null=True, db_column='rotlinid', blank=True)
    rotfrom = models.ForeignKey(Trn, null=True, db_column='rotfrom', blank=True, related_name=""rotfrom"")
    rotto = models.ForeignKey(Trn, null=True, db_column='rotto', blank=True, related_name=""rotto"")
    rotkm = models.FloatField(null=True, blank=True)
    rottimemnt = models.IntegerField(null=True, blank=True)
    rotprice = models.FloatField(null=True, blank=True)
    rotisinterchange = models.BooleanField(default=False, null=False, blank=False, verbose_name=""is interchange?"")
    rotisactive = models.BooleanField(default=True, null=False, blank=False, verbose_name=""is active?"")
    rotdesc = models.CharField(max_length=225, blank=True)

    def __unicode__(self):
        if self.rotfrom is None:
            return ""to "" + str(self.rotto)
        elif self.rotto is None:
            return ""from "" + str(self.rotfrom)
        else:
            return ""{0} to {1}"".format(self.rotfrom.bsnid.bsnname, self.rotto.bsnid.bsnname)

    class Meta:
        db_table = u'rot'
        verbose_name = ""Route""
}}}

The model are generated from inspectdb, and all is working when I try to save one by one manually; both from Django admin and from the Django console, and also from a Pilot.py file that I myself created to fill the database automatically whenever I want, with initial data.

But, when I go to admin page for LIN, that itself is a 'child' of BSN and that itself is used to determine and show the ROT; I got the multivalued key error. I have tried to understand this error, but I lost myself. I have no one at hand to help except than the Django community here. So, please let me know where I am wrong at.

Here are the Admin code.
{{{#!python
class RotAdmin(admin.ModelAdmin):
    """"""admin page for route""""""
    fieldsets = [
        (None, {'fields': ['rotlin', 'rotfrom', 'rotto', 'rotisinterchange', 'rotisactive']}),
        (""Distance"", {'fields': ['rotkm', 'rottimemnt', 'rotprice']}),
        (""Description"", {'fields': ['rotdesc']})
    ]
admin.site.register(Rot, RotAdmin)

class RotGridsTabular(admin.TabularInline):
    fields = ['rotfrom', 'rotto', 'rotkm', 'rottimemnt', 'rotprice', 'rotisinterchange', 'rotisactive']
    model = Rot
    extra = 0

class LinAdmin(admin.ModelAdmin):
    """"""admin page for line""""""
    fields = ['linbsn']
    inlines = [RotGridsTabular]
admin.site.register(Lin, LinAdmin)
}}}

Note: when I add the ROT record from the ROT admin, it works; when I add the ROT record from LIN admin, it crashes and throws the Multivalued key error."	Bug	closed	contrib.admin	1.4	Normal	duplicate	MultiValueDictKeyError		Unreviewed	0	0	0	0	0	0
