I need to get access to m2m model from intermediate table name.
Example models:
class Person(models.Model):
name = models.CharField(max_length=128)
class Group(models.Model):
name = models.CharField(max_length=128)
members = models.ManyToManyField(Person)
so the table name is group_person, how can i access to it's model only from name?
Due to circumstances i can't use through/etc from parent/related model.
Im getting list of m2m tables names like this:
m2m_fields = model_class._meta.local_many_to_many
if m2m_fields:
for field in m2m_fields:
table = field.remote_field.through
intermediate_table_name = table.__name__
while iterating over some models
Thanks! Sorry for bad eng:)
question from:
https://stackoverflow.com/questions/65877629/get-m2m-model-from-intermediate-table-name 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…