mirror of
https://github.com/ansible/awx.git
synced 2026-01-12 18:40:01 -03:30
Fixed ImplicitRoleField and ImplicitResourceField's from being too lazy
This ensures that the role and resource fields get created and bound automatically without having to explicitly access them a first time.
This commit is contained in:
parent
1035a6737e
commit
c6b2e509fd
@ -2,6 +2,7 @@
|
||||
# All Rights Reserved.
|
||||
|
||||
# Django
|
||||
from django.db.models.signals import post_save, post_init
|
||||
from django.db import models
|
||||
from django.db.models.fields.related import SingleRelatedObjectDescriptor
|
||||
from django.db.models.fields.related import ReverseSingleRelatedObjectDescriptor
|
||||
@ -91,7 +92,11 @@ class ImplicitResourceField(models.ForeignKey):
|
||||
def contribute_to_class(self, cls, name):
|
||||
super(ImplicitResourceField, self).contribute_to_class(cls, name)
|
||||
setattr(cls, self.name, ResourceFieldDescriptor(self.parent_resource, self))
|
||||
post_save.connect(self._save, cls, True)
|
||||
|
||||
def _save(self, instance, *args, **kwargs):
|
||||
# Ensure that our field gets initialized after our first save
|
||||
getattr(instance, self.name)
|
||||
|
||||
|
||||
class ImplicitRoleDescriptor(ReverseSingleRelatedObjectDescriptor):
|
||||
@ -185,4 +190,8 @@ class ImplicitRoleField(models.ForeignKey):
|
||||
self
|
||||
)
|
||||
)
|
||||
post_save.connect(self._save, cls, True)
|
||||
|
||||
def _save(self, instance, *args, **kwargs):
|
||||
# Ensure that our field gets initialized after our first save
|
||||
getattr(instance, self.name)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user