开发者

Change the default name of relationship in django admin

开发者 https://www.devze.com 2023-04-07 01:50 出处:网络
I have a ManyToMany relationship follow as: class Subtopic(models.Model): id = models.PositiveIntegerField(primary_key=True)

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

精彩评论

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

关注公众号