From the example of Django Book, I understand if I create models as following:
from xxx import B
class A(models.Model):
b = ManyToManyField(B)
>
Under the hood, Django creates automatically a through model. It is possible to modify this automatic model foreign key column names.
I could not test the implications on all scenarios, so far it works properly for me.
Using Django 1.8 and onwards' _meta api:
class Person(models.Model):
pass
class Group(models.Model):
members = models.ManyToManyField(Person)
Group.members.through._meta.get_field('person').column = 'alt_person_id'
Group.members.through._meta.get_field('group' ).column = 'alt_group_id'
# Prior to Django 1.8 _meta can also be used, but is more hackish than this
Group.members.through.person.field.column = 'alt_person_id'
Group.members.through.group .field.column = 'alt_group_id'