# List all models, incl. those in subfolders

**URL:** <https://forum.djangoproject.com/t/list-all-models-incl-those-in-subfolders/18501>\
**Category:** Forms & APIs\
**Created:** [January 29, 2023, 6:32am UTC](https://forum.djangoproject.com/t/list-all-models-incl-those-in-subfolders/18501 "2023-01-29T06:32:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![buswedg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/buswedg/32/3229_2.png) [@buswedg](https://forum.djangoproject.com/u/buswedg)\
**Post date:** [January 29, 2023, 6:32am UTC](https://forum.djangoproject.com/t/list-all-models-incl-those-in-subfolders/18501/1 "2023-01-29T06:32:38Z")

</div>

I have organized some of my app models into sub directories. Everything runs fine (i.e. the models are recognized for migrations etc.). But I’m curious on the best way to get a complete list of all models for all of my apps, including those within sub dirs. Not that the below doesn’t inculde sub dir models.

```auto
apps.get_models()

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [January 29, 2023, 10:51am UTC](https://forum.djangoproject.com/t/list-all-models-incl-those-in-subfolders/18501/2 "2023-01-29T10:51:16Z")

</div>

Can you provide a minimal example of what you’re trying? (Along with a more detailed description of your module layouts.)

What I’m mostly concerned about is _where_ you’re trying to call that function.

From the docs for get\_models at: [Applications | Django documentation | Django](https://docs.djangoproject.com/en/4.1/ref/applications/#django.apps.AppConfig.get_models)

> Requires the app registry to be fully populated.

If this is something you’re trying to use during the Django “start up” process, I can understand why you might not be getting complete results.

---

<div class="post-metadata">

**Author:** ![buswedg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/buswedg/32/3229_2.png) [@buswedg](https://forum.djangoproject.com/u/buswedg)\
**Post date:** [January 29, 2023, 7:30pm UTC](https://forum.djangoproject.com/t/list-all-models-incl-those-in-subfolders/18501/3 "2023-01-29T19:30:57Z")

</div>

I don’t know if this is ‘best practice’.

But I ended up including model imports for any subfolders in the base apps.py like so:

```auto
class Config(AppConfig):
    default_auto_field = "django.db.models.AutoField"
    label = "XXX"
    name = "apps.XXX.XXX"

    @staticmethod
    def imports():
        import apps.XXX.signals # noqa

        from apps.XXX.XXX import models # noqa

    def ready(self):
        self.imports()

```

I then ensure that when I’m going to loop through all models for that particular app, that I just call on the static imports method above. e.g.

```auto
app_config = apps.get_app_config('XXX')

app_config.imports()

models = app_config.get_models()

```

Which has solved this issue for me at the moment.
