Try to create the model only after the post_migrate signal

This commit is contained in:
Roberto Rosario
2014-07-18 18:35:10 -04:00
parent ba71c80b32
commit 206b5c1a56
2 changed files with 4 additions and 10 deletions

View File

@@ -1,6 +1,5 @@
from __future__ import absolute_import
from django.db import transaction
from django.db.utils import DatabaseError
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _
@@ -16,18 +15,13 @@ from .links import link_menu_link, link_namespace_details, link_namespace_list
from .models import Installation
@receiver(post_migrate, dispatch_uid='trigger_first_time')
@receiver(post_migrate, dispatch_uid='trigger_first_time', sender=Installation)
def trigger_first_time(sender, **kwargs):
if kwargs['app'] == 'installation':
details, created = Installation.objects.get_or_create()
if created:
details.is_first_run = True
details.save()
Installation.objects.get_or_create()
def check_first_run():
try:
with transaction.atomic():
details = Installation.objects.get()
except DatabaseError:
# Avoid database errors when the app tables haven't been created yet

View File

@@ -39,7 +39,7 @@ from .literals import (FORM_SUBMIT_URL, FORM_KEY, FORM_RECEIVER_FIELD,
class Installation(SingletonModel):
_properties = SortedDict()
is_first_run = models.BooleanField(default=False)
is_first_run = models.BooleanField(default=True)
uuid = models.CharField(max_length=48, blank=True, default=lambda: unicode(uuid.uuid4()))
def add_property(self, property_instance):