Coverage for django_napse/utils/findable_class.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.4.3, created at 2024-03-12 13:49 +0000

1from django.apps import apps 

2 

3 

4class FindableClass: 

5 def find(self): 

6 """Find the correct subclass of this django model.""" 

7 instance = self 

8 

9 for subclass in self.__class__.__subclasses__(): 

10 django_model = apps.get_model(self._meta.app_label, f"{subclass.__name__}") 

11 try: 

12 instance = django_model.objects.get(pk=instance.pk) 

13 break 

14 except django_model.DoesNotExist: 

15 pass 

16 return instance