1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

Refactor m2m_changed so reverse works

This commit is contained in:
Wayne Witzel III 2016-03-11 15:18:24 -05:00
parent 31a461956a
commit 45483fb057

View File

@ -199,16 +199,17 @@ class ImplicitRoleField(models.ForeignKey):
if '.' in field_attr:
raise Exception('Referencing deep roles through ManyToMany fields is unsupported.')
reverse = type(field) is ReverseManyRelatedObjectsDescriptor
if reverse:
m2m_changed.connect(self.m2m_update(field_attr, reverse), field.through, weak=False)
if type(field) is ReverseManyRelatedObjectsDescriptor:
sender = field.through
else:
m2m_changed.connect(self.m2m_update(field_attr, reverse), field.related.through, weak=False)
sender = field.related.through
def m2m_update(self, field_attr, _reverse):
def _m2m_update(instance, action, model, pk_set, **kwargs):
m2m_changed.connect(self.m2m_update(field_attr), sender, weak=False)
def m2m_update(self, field_attr):
def _m2m_update(instance, action, model, pk_set, reverse, **kwargs):
if action == 'post_add' or action == 'pre_remove':
if _reverse:
if reverse:
for pk in pk_set:
obj = model.objects.get(pk=pk)
if action == 'post_add':