Opened 16 years ago
Last modified 16 years ago
#8748 closed
Problems in admin/form with primary keys in an abstract superclass — at Version 1
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | contrib.admin | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
My models.py has an abstract superclass, which defines (beside other things) the primary key (as a UID):
class StdHeader(models.Model): """ Standard header. Each database relation starts with these attributes. """ pkey = models.CharField(max_length=40, primary_key=True, editable=True) # primary key; an UID def save(self): """update of all std header attributes""" #... if self.pkey == None or len(self.pkey)==0: self.pkey = uids.uid(self.__class__.__name__) super(StdHeader,self).save() class Meta: abstract = True
Now: in later SVN versions (specifically in SVN 8785) there are "KeyErrors"
in dependend Models:
I.E:
class Person(StdHeader): familyname = models.CharField(_('Familyname'),max_length=30) #... class Address(StdHeader): person = models.ForeignKey(Person, null=True, to_field="pkey") street = models.CharField(max_length=40, blank=True) #...
Adding a record to Person results in:
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/loader_tags.py", line 123, in render return t.render(context) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py", line 176, in render return self.nodelist.render(context) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py", line 768, in render bits.append(self.render_node(node, context)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py", line 81, in render_node raise wrapped TemplateSyntaxError: Caught an exception while rendering: "Key 'pkey' not found in Form" Original Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py", line 71, in render_node result = node.render(context) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/defaulttags.py", line 148, in render nodelist.append(node.render(context)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/debug.py", line 87, in render output = force_unicode(self.filter_expression.resolve(context)) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py", line 535, in resolve obj = self.var.resolve(context) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py", line 676, in resolve value = self._resolve_lookup(context) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/template/__init__.py", line 711, in _resolve_lookup current = current() File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/helpers.py", line 134, in pk_field return AdminField(self.form, self.formset._pk_field.name, False) File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/contrib/admin/helpers.py", line 77, in __init__ self.field = form[field] # A django.forms.BoundField instance File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/django/forms/forms.py", line 105, in __getitem__ raise KeyError('Key %r not found in Form' % name) KeyError: "Key 'pkey' not found in Form"
Note: There might be a relation to ticket #8562 as i got the same trace when editing/saving.
Note:
See TracTickets
for help on using tickets.
Fixed description formatting.