heya,
I have a small Django app that contains a list of Df (disk-free)
reports.
"DfReport" has a ForeignKey to "Filesystem" model, which has a
ForeignKey to "Device". (i.e. Devices has filesystems, each filesystem
has a DfReport).
I'm getting an error in the admin when I attempt to display the
list_display page for a "DfReport" model.
TemplateSyntaxError at /admin/report/dfreport/add/
Caught TypeError while rendering: coercing to Unicode: need string
or buffer, Device found
I've traced the error to the __unicode__ method for one of the
ForeignKey fields on DfReport being displayed.
The issue is, Filesystem has __unicode__ set to print the server on
which it's reporting. Using the following causes the
TemplateSyntaxError:
class Filesystem(models.Model):
name = models.CharField(max_length=50)
#description = models.CharField(max_length=100)
description = models.TextField()
server = models.ForeignKey(Device)
def __unicode__(self):
return self.name + ' on device ' + self.server
However, if I change self.server to "self.server.name", it works. The
weird thing is - Device (which server points to), has a __unicode__
method defined as well. Shouldn't calling self.server just use the
__unicode__ method on Device, instead of needing me to explicitly call
self.server.name?
class Device(models.Model):
name = models.CharField(max_length=50)
#description = models.CharField(max_length=100)
description = models.TextField()
location = models.ForeignKey(Location)
def __unicode__(self):
return self.name
class Meta:
ordering = ['name']
Or have I got a wrong understanding of how this works?
Cheers,
Victor
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.