Запись в базу данных Django - Python
Формулировка задачи:
Только начал изучать джанго
имеются модели в Django проекте
import models
File "C:\Users\Дмитрий\Desktop\NV08C_Controller_View\NV08C_Controller\viewModul\viewNV08C\models.py", line 3, in
class GNSSData(models.Model):
File "C:\Python35-32\lib\site-packages\django\db\models\base.py", line 100, in __new__
app_config = apps.get_containing_app_config(module)
File "C:\Python35-32\lib\site-packages\django\apps\registry.py", line 244, in get_containing_app_config
self.check_apps_ready()
File "C:\Python35-32\lib\site-packages\django\apps\registry.py", line 127, in check_apps_ready
raise AppRegistryNotReady("Apps aren't loaded yet.")
django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Через админпанель записи добавляются, редактруются и тд. В общем проект корректно работает.
Пытаюсь не из теминала(!), а из другого проекта записать в БД данные
выкидывает django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.
Предусмотренна ли вообще такая возможность?
Traceback (most recent call last):
File "dbTest.py", line 1, in
Решение задачи: «Запись в базу данных Django»
textual
Листинг программы
# -*- encoding: utf-8 -*-
import os
import time
import django
import schedule
from django.conf import settings
def execute_command():
from django.contrib.auth.models import User
from News.models import News
from django.utils import timezone
def create_notification(message, for_user):
News.objects.create(
title=message,
is_important=True,
notify_for_user=for_user,
location_url=settings.CRON_PAYMENT_URL
)
try:
django.setup()
users = User.objects.filter(
profile__is_active=True,
# profile__stream__day_for_second_pay__lt=timezone.now().date(),
profile__cherry_pae=True,
profile__is_paid=False
)
for user in users:
delta = (user.profile.stream.day_for_second_pay - timezone.now().date()).days
if delta < 0:
user.profile.is_active = False
user.save()
create_notification(
'Ваш аккаунт деактивирован!', user
)
elif delta < settings.CRON_DAY_DELTA:
create_notification(
'Дней до даты оплаты: {}'.format(delta), user
)
else:
print('Skip')
except Exception as e:
print(e)
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Panel.settings")
schedule.every().day.at(settings.CRON_TIME).do(execute_command)
while True:
schedule.run_pending()
time.sleep(1)