Explicitly prefetch policy in graphql

This commit is contained in:
Brian Tiemann 2024-10-22 18:42:33 -04:00
parent 24caa3bf1f
commit ae93ce848b
3 changed files with 5 additions and 8 deletions

View File

@ -291,7 +291,7 @@ class VLANTranslationPolicyType(NetBoxObjectType):
filters=VLANTranslationRuleFilter filters=VLANTranslationRuleFilter
) )
class VLANTranslationRuleType(NetBoxObjectType): class VLANTranslationRuleType(NetBoxObjectType):
policy: Annotated["VLANTranslationPolicyType", strawberry.lazy('ipam.graphql.types')] | None policy: Annotated["VLANTranslationPolicyType", strawberry.lazy('ipam.graphql.types')] = strawberry_django.field(select_related=["policy"])
@strawberry_django.type( @strawberry_django.type(

View File

@ -315,6 +315,9 @@ class VLANTranslationRule(NetBoxModel):
), ),
help_text=_("Numeric VLAN ID (1-4094)") help_text=_("Numeric VLAN ID (1-4094)")
) )
prerequisite_models = (
'ipam.VLANTranslationPolicy',
)
class Meta: class Meta:
verbose_name = _('VLAN translation rule') verbose_name = _('VLAN translation rule')
@ -331,8 +334,7 @@ class VLANTranslationRule(NetBoxModel):
) )
def __str__(self): def __str__(self):
return f'{self.local_vid} -> {self.remote_vid}' return f'{self.local_vid} -> {self.remote_vid} ({self.policy})'
# return f'{self.local_vid} -> {self.remote_vid} ({self.policy})'
def to_objectchange(self, action): def to_objectchange(self, action):
objectchange = super().to_objectchange(action) objectchange = super().to_objectchange(action)

View File

@ -1065,10 +1065,6 @@ class VLANTranslationPolicyTest(APIViewTestCases.APIViewTestCase):
class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase): class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase):
model = VLANTranslationRule model = VLANTranslationRule
brief_fields = ['id', 'local_vid', 'policy', 'remote_vid',] brief_fields = ['id', 'local_vid', 'policy', 'remote_vid',]
bulk_update_data = {
'policy': '109',
'remote_vid': '209',
}
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
@ -1103,7 +1099,6 @@ class VLANTranslationRuleTest(APIViewTestCases.APIViewTestCase):
), ),
) )
VLANTranslationRule.objects.bulk_create(vlan_translation_rules) VLANTranslationRule.objects.bulk_create(vlan_translation_rules)
print(VLANTranslationRule.objects.all().values('id', 'policy'))
cls.create_data = [ cls.create_data = [
{ {