I have a Django command which I can run using manage.py. The command imports django.conf.settings, then I grab Songs from the database to update bits of the settings:
from django.conf import settings
from music.models import Song
class Command(BaseCommand):
def handle(self, **options):
new_songs = SongSerializer(Song.objects.all(), many=True).data
settings.SONGS_TO_EXPORT = new_songs
print(settings.SONGS_TO_EXPORT)
# ...
The confusing behaviour is:
When I run the command using
manage.py, I can confirm I get a fresh copy of the settings and the UPDATED content ofsettings.SONGS_TO_EXPORTis printed out.When I run the command in another app using Django's
call_command, I get an old (perhaps cached???) version of the settings and the content ofsettings.SONGS_TO_EXPORTis just old. Even if I run the command withmanage.pyfirst, I still get a non-updated version of the settings in thecall_commandversion.
My aim is to get the same results with call_command.