Refactor fixtures from JSON to Python

This commit is contained in:
Seamus Johnston 2022-12-21 10:05:03 -06:00
parent ba7c0b9e8d
commit df265b10f8
No known key found for this signature in database
GPG key ID: 2F21225985069105
10 changed files with 426 additions and 270 deletions

View file

@ -1,9 +1,16 @@
from django.db.models.signals import post_save
import logging
from django.conf import settings
from django.core.management import call_command
from django.db.models.signals import post_save, post_migrate
from django.dispatch import receiver
from .models import User, UserProfile
logger = logging.getLogger(__name__)
@receiver(post_save, sender=User)
def handle_profile(sender, instance, **kwargs):
@ -21,3 +28,13 @@ def handle_profile(sender, instance, **kwargs):
instance.userprofile.save()
else:
UserProfile.objects.create(user=instance)
@receiver(post_migrate)
def handle_loaddata(**kwargs):
"""Attempt to load test fixtures when in DEBUG mode."""
if settings.DEBUG:
try:
call_command("load")
except Exception as e:
logger.warning(e)