55from django .contrib .contenttypes .models import ContentType
66
77from app .models import Person
8+ from app .models import PersonType
89from app .tests import APITestCase
910from app .tests .custom_fields .factories import CustomFieldFactory
1011from app .tests .custom_fields .factories import CustomValueFactory
1112from app .tests .factories import PersonFactory
13+ from app .tests .factories import PersonTypeFactory
1214from django_features .custom_fields .models import CustomField
1315
1416
@@ -18,7 +20,9 @@ class CustomFieldBaseModelManagerTest(APITestCase):
1820
1921 def setUp (self ) -> None :
2022 self .person_ct = ContentType .objects .get_for_model (Person )
21- self .person : Person = PersonFactory () # type: ignore
23+ self .person_type_1 : PersonType = PersonTypeFactory () # type: ignore
24+ self .person_type_2 : PersonType = PersonTypeFactory () # type: ignore
25+ self .person : Person = PersonFactory (person_type = self .person_type_1 ) # type: ignore
2226
2327 def test_custom_field_base_manager_annotate_custom_field_keys (self ) -> None :
2428 CustomFieldFactory (identifier = "birthday" , content_type = self .person_ct )
@@ -27,6 +31,20 @@ def test_custom_field_base_manager_annotate_custom_field_keys(self) -> None:
2731 ["birthday" , "hobby" ], Person .objects .first ().custom_field_keys
2832 )
2933
34+ def test_custom_field_base_manager_annotate_only_type_specific_fields (self ) -> None :
35+ CustomFieldFactory (
36+ identifier = "birthday" ,
37+ content_type = self .person_ct ,
38+ type_object = self .person_type_1 ,
39+ )
40+ CustomFieldFactory (
41+ identifier = "hobby" ,
42+ content_type = self .person_ct ,
43+ type_object = self .person_type_2 ,
44+ )
45+ self .person .refresh_with_custom_fields ()
46+ self .assertEqual (["birthday" ], Person .objects .first ().custom_field_keys )
47+
3048 def test_custom_field_base_manager_annotate_char_value (self ) -> None :
3149 field = CustomFieldFactory (
3250 identifier = "char_value" ,
0 commit comments