Hi all,
Newbie here . Please have mercy (and patience)!
[EDIT: solved, see my comment]
I created a small script that reads a CSV (a list of filenames) and creates objects accordingly:
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'myproject.settings')
import django
django.setup()
import csv
import sys
from myapp.models import Campaign, Annotation
campaign_name = "a_great_name"
path_to_csv = "filenames.csv"
with open(path_to_csv) as f:
reader = csv.reader(f)
filenames = [i[0] for i in reader]
new_campaign = Campaign.objects.create(name=campaign_name)
for i in filenames:
new_annotation = Annotation(
campaign=new_campaign,
asset_loc = i)
new_annotation.save()
I saved this script at the root of my project:
myrepo/populator.py
and it worked fine.
ā¦ until I decided to move it into a subfolder of my project (itās a bit like an admin tool that should rarely be used):
myrepo/useful_tools/import_filenames/populator.py
Now, when I try to run it, I get this error: ModuleNotFoundError: No module named 'myproject'
Iām having a hard time understanding why this happens exactly and as a consequence, how to fix it. The various StackOverflow threads Iāve read were not easy enough for my rookie brain.
Thank you in advance for your help!