In my django rest project I have created total 5 apps with corresponding models with their own serializers (Authentication (-> Profile), crc (-> Card, Responsibility, Collaborator), project (-> Project), scenarios (-> Scenario) and tasks (-> Task)). Models also have associations with each other like
class Project(models.Model):
stakeholders = models.ManyToManyField(User, blank=True)
class Profile(models.Model):
user = models.OneToOneField(User, blank=True, on_delete=models.CASCADE, )
class Scenario(models.Model):
stakeholder = models.ForeignKey(User, related_name='scenarios', blank=True,)
project = models.ForeignKey(Project, related_name='project_scenarios',)
tasks = models.ManyToManyField('tasks.Task', blank=True)
class Task(models.Model):
stakeholder = models.ForeignKey(User, related_name='tasks', blank=True, )
project = models.ForeignKey(Project, related_name='project_tasks' )
I want to list all the models and their corresponding methods that I have written. I tried
import django.apps
print(django.apps.apps.get_models())
but this lists all the classes it knows about:
[<class 'django.contrib.admin.models.LogEntry'>,
<class 'django.contrib.auth.models.Permission'>,
<class 'django.contrib.auth.models.Group'>,
<class 'django.contrib.auth.models.User'>,
<class 'django.contrib.contenttypes.models.ContentType'>,
<class 'django.contrib.sessions.models.Session'>,
<class 'rest_framework.authtoken.models.Token'>,
<class 'django.contrib.sites.models.Site'>,
<class 'allauth.account.models.EmailAddress'>,
<class 'allauth.account.models.EmailConfirmation'>,
<class 'authentication.models.Profile'>,
<class 'project.models.Project'>,
<class 'tasks.models.Task'>,
<class 'scenarios.models.Scenario'>,
<class 'crc.models.Card'>,
<class 'crc.models.Responsibility'>,
<class 'crc.models.Collaborator'>]
How can I retrieve only those models and their corresponding methods?
UPDATE:
I tried something like:
@api_view(['GET'])
def class_list(request):
my_apps=['authentication', 'crc', 'moel_views', 'project', 'scenarios', 'tasks']
my_app_models = {name: apps.all_models[name] for name in my_apps}
return Response(my_app_models)
but it throws class not JSON serializable
error