add "self" 2008/4/14, Malcolm Tredinnick <[EMAIL PROTECTED]>: > > > > On Sun, 2008-04-13 at 22:04 -0700, Brandon Taylor wrote: > > Hello everyone, > > > > I'm pretty new to Django, so please bear with me. > > > > When I'm defining a model, and I want to return a value to use in the > > admin for the information to be displayed as such: > > > > from django.db import models > > > > class Link(models.Model): > > name = models.CharField() > > url = models.CharField() > > position = models.PositiveSmallIntegerField() > > > > def __unicode__(self): > > return name > > > That will give you a NameError, since "name" does not exist. You want to > do "return self.name" there. > > > > Is it possible to concatenate fields for the def__unicode__(self) > > method? I can't seem to find a way to do that, and was just wondering > > if it's possible? > > > A __unicode__ method must return a unicode string. That's all. How you > construct that string is entirely up to you. If you want to construct it > by putting various attribute values together, that's fine. It's just > Python. So, for example, > > return u"%s %s" % (self.name, self.url) > > would return a concatenation of the name and url attributes. Season to > taste. > > Regards, > Malcolm > > > -- > Honk if you love peace and quiet. > http://www.pointy-stick.com/blog/ > > > > > >
--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com 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 -~----------~----~----~----~------~----~------~--~---