开发者

How can I change name of option in django select box

开发者 https://www.devze.com 2023-01-05 02:54 出处:网络
I got 2 models class Category(models.Model): name = mod开发者_JAVA百科els.CharField(max_length=30, unique=True)

I got 2 models

class Category(models.Model):
    name = mod开发者_JAVA百科els.CharField(max_length=30, unique=True)
class Post(models.Model): 
    ......
    category = models.ForeginKey(Category)
    ........

And when I create a form, in select box i got options "Category object", but i would like to display name of category, i am sure it's basic, just missed it in doc's :C


class Category(models.Model):
   name = models.CharField(max_length=30, unique=True)

   def __unicode__(self):
        return self.name
0

精彩评论

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