Hi,
I am trying to use a related object's attribute as part of the __repr__()
function, and am running into trouble.
from django.core import meta
class Foo(meta.Model):
name = meta.CharField(maxlength=255)
def __repr__(self):
return self.name
class META:
admin = meta.Admin()
class Bar(meta.Model):
name = meta.CharField(maxlength=255)
foo = meta.ForeignKey(Foo)
def __repr__(self):
return self.name + " " + self.foo.name
class META:
admin = meta.Admin()
With this setup, I can create a Bar in the admin page, but when I hit
"submit", it throws an exception. Unfortunately the exception gets
clobbered, but I added a quick one-liner hack to print it out before it gets
clobbered, and this is the error:
'Bar' object has no attribute 'foo'
What am I missing?
Thanks,
Jason Pepas