How do I reference my model in a nested folder structure to dump data in Django 3.2?

322 Views Asked by At

I'm using Django 3.2 and Python 3.9. I have this project directory setup

+ cbapp
    - manage.py
    - settings.py
    + models
        - __init__.py
        - crypto_currency.py

In my settings.py file, I have

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'cbapp',
]

I want to dump some data to a fixtures file, so I tried

$ python3 manage.py dumpdata cbapp.models.crypto_currency  > ./cbapp/fixtures/crypto_currency.json
CommandError: No installed app with label 'cbapp.models.crypto_currency'.

What's the proper way to reference my model to dump data?

1

There are 1 best solutions below

2
Felix Eklöf On

Firstly in cbapp/models/__init__.py I think you have to import all models from crypto_currency.py. Like so: from .crypto_currency import *

Then you should be able to use (Replace CryptoModel with the name of your model):

python3 manage.py dumpdata cbapp.CryptoModel > ./cbapp/fixtures/crypto_currency.json