Try to create the model only after the post_migrate signal
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.db import transaction
|
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
@@ -16,19 +15,14 @@ from .links import link_menu_link, link_namespace_details, link_namespace_list
|
|||||||
from .models import Installation
|
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):
|
def trigger_first_time(sender, **kwargs):
|
||||||
if kwargs['app'] == 'installation':
|
Installation.objects.get_or_create()
|
||||||
details, created = Installation.objects.get_or_create()
|
|
||||||
if created:
|
|
||||||
details.is_first_run = True
|
|
||||||
details.save()
|
|
||||||
|
|
||||||
|
|
||||||
def check_first_run():
|
def check_first_run():
|
||||||
try:
|
try:
|
||||||
with transaction.atomic():
|
details = Installation.objects.get()
|
||||||
details = Installation.objects.get()
|
|
||||||
except DatabaseError:
|
except DatabaseError:
|
||||||
# Avoid database errors when the app tables haven't been created yet
|
# Avoid database errors when the app tables haven't been created yet
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ from .literals import (FORM_SUBMIT_URL, FORM_KEY, FORM_RECEIVER_FIELD,
|
|||||||
class Installation(SingletonModel):
|
class Installation(SingletonModel):
|
||||||
_properties = SortedDict()
|
_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()))
|
uuid = models.CharField(max_length=48, blank=True, default=lambda: unicode(uuid.uuid4()))
|
||||||
|
|
||||||
def add_property(self, property_instance):
|
def add_property(self, property_instance):
|
||||||
|
|||||||
Reference in New Issue
Block a user