AttributeError: модуль ' ' не имеет атрибута 'Command'

В моем проекте Django есть файл (модуль), который используется для загрузки данных csv.

project/apps/patients/management/commands/load_patient_data.py

Внутри файла (модуля):

import psycopg2
import csv
conn = psycopg2.connect(host='localhost', dbname='patientdb',user='username',password='password',port='')
cur = conn.cursor()

with open(r'apps/patients/management/commands/events.csv') as csvfile:
        spamreader = csv.DictReader(csvfile, delimiter=',' ,quotechar=' ')
        for row in spamreader:
            cur.execute(f"""INSERT INTO patients_event (patient_id, event_type_id , event_value ,event_unit, event_time) VALUES
                  ('{row['PATIENT ID']}','{row['EVENT TYPE']}','{row['EVENT VALUE']}',
                   '{row['EVENT UNIT']}','{row['EVENT TIME']}')""")
conn.commit()

Когда я запускаю:

 python manage.py load_patient_data

Ошибка:

AttributeError: module 'apps.patients.management.commands.load_patient_data' has no attribute 'Command'

Любой друг может помочь?

В load_patient_data.py файле

Напишите продолжение

from django.core.management.base import BaseCommand, CommandError

class Command(BaseCommand):

    def handle(self, *args, **options):
        import psycopg2
        import csv
        conn = psycopg2.connect(host='localhost', dbname='patientdb', user='username', password='password', port='')
        cur = conn.cursor()
    
        with open(r'apps/patients/management/commands/events.csv') as csvfile:
            spamreader = csv.DictReader(csvfile, delimiter=',', quotechar=' ')
            for row in spamreader:
                cur.execute(f"""INSERT INTO patients_event (patient_id, event_type_id , event_value ,event_unit, event_time) VALUES
                          ('{row['PATIENT ID']}','{row['EVENT TYPE']}','{row['EVENT VALUE']}',
                           '{row['EVENT UNIT']}','{row['EVENT TIME']}')""")
        conn.commit()

Затем просто выполните python manage.py load_patient_data

Вернуться на верх