mirror of
https://github.com/ansible/awx.git
synced 2024-11-01 08:21:15 +03:00
Refactor m2m_changed so reverse works
This commit is contained in:
parent
31a461956a
commit
45483fb057
@ -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':
|
||||
|
Loading…
Reference in New Issue
Block a user