开发者

Define Self as multiple attributes in Django

开发者 https://www.devze.com 2023-04-08 19:18 出处:网络
I\'m new to Django and building my first app. I want locations in my Admin section to be displayed by a combination of different attributes from the model.

I'm new to Django and building my first app.

I want locations in my Admin section to be displayed by a combination of different attributes from the model.

Currently they are shown by the icon by using the following code.

    def __unicode__(self):
    return self.icon

I want to be able to add my other two attributes to this code so that th开发者_JS百科e result will look like.

"Icon(Attribute1, Attribute2)"

How can I edit the code to do this?


If I have understood you correctly then the following should produce the result that you are looking for (but you'll need to edit the attribute names):

def __unicode__(self):
    return u"{0} ({1}, {2})".format(self.icon, self.attrib1, self.attrib2)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号