开发者

Django admin many to many table name

Can I specify the name开发者_开发技巧 I want for the many to many table?


Yes. See Table Names for all of the exciting details.

Update: OK, then perhaps the related_name option is what you are looking for. There are some caveats covered here.

Updatex2: OK, Kelvin gets a star for answering his own question! It's been an age since I perused the Django Meta Model Options, but, in retrospect, that's where we should have started.

BTW, wandering through the django/db/ code on only half a cup of coffee is definitely a challenge.


You define the table name using the db_table option when declaring the ManyToManyField attribute. See example below:

class revision(models.Model):
    revision_id = models.AutoField(primary_key=True)
    issue_list = models.ManyToManyField(issue, related_name='revisions', db_table='issue_revision')

related_name is the field by which this class will be seen by issue, meaning, you will access it as my_issue.revisions(). And the table being used in the DB is named issue_revision.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜