rxin
rxin

Reputation: 1796

django admin app error (Model with property field): global name 'full_name' is not defined

This is my model:

class Author(models.Model):

    first_name = models.CharField(max_length=200)
    last_name = models.CharField(max_length=200)
    middle_name = models.CharField(max_length=200, blank=True)

    def __unicode__(self):
        return full_name

    def _get_full_name(self):
        "Returns the person's full name."
        if self.middle_name == '':
            return "%s %s" % (self.first_name, self.last_name)
        else:
            return "%s %s %s" % (self.first_name, self.middle_name, self.last_name)
    full_name = property(_get_full_name)

Everything is fine except when I go into admin interface, I see

TemplateSyntaxError at /bibbase2/admin/bibbase2/author/ Caught an exception while rendering: global name 'full_name' is not defined

It seems like the built-in admin app doesn't work with a property field. Is there something wrong with my code?

Upvotes: 1

Views: 1110

Answers (1)

Davor Lucic
Davor Lucic

Reputation: 29420

def __unicode__(self):
        return full_name

Should be:

def __unicode__(self):
        return self.full_name

Upvotes: 7

Related Questions