开发者

Change the default name of relationship in django admin

I have a ManyToMany relationship follow as:

class Subtopic(models.Model):
   id = models.PositiveIntegerField(primary_key=True)
   name = models.CharField(max_length=128)

   class Meta:
      verbose_name = 'Subtopic'

   def __unicode__(self):
      return self.name

class Question(models.Model):
   qid = models.PositiveIntegerField(primary_key=True)
   subtopics = models.ManyToManyField(Subtopic)

   class Meta:
      verbose_name = 'Question'

In the admin interface, I would like to change the default nam开发者_StackOverflow中文版es in this picture.

http://flic.kr/p/apx3j8

The first name is the relationship of two class such as Subtopic and Question. Second is the name of Subtopic class. And finally is Question class

Django model automatically generates an intermediary table namely Question_Subtopics and I can not meddle in this table.

Please help me to achieve it.

Thanks.


that text is filled with __unicode__, which is similar to java's toString().

class Subtopic(models.Model):
    ...
    def __unicode__(self):
        return self.name

Just do that, and you'll be fine :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜