2014-07-08 16:37:38 +00:00
|
|
|
from django.apps import AppConfig
|
|
|
|
from django.contrib.contenttypes import generic
|
|
|
|
|
2014-07-09 16:17:43 +00:00
|
|
|
from orchestra.utils import running_syncdb
|
|
|
|
|
2014-07-08 16:37:38 +00:00
|
|
|
|
|
|
|
class ResourcesConfig(AppConfig):
|
|
|
|
name = 'orchestra.apps.resources'
|
|
|
|
verbose_name = 'Resources'
|
|
|
|
|
|
|
|
def ready(self):
|
|
|
|
from .models import Resource
|
|
|
|
# TODO execute on Resource.save()
|
2014-07-09 16:17:43 +00:00
|
|
|
if not running_syncdb():
|
|
|
|
relation = generic.GenericRelation('resources.ResourceData')
|
|
|
|
for resources in Resource.group_by_content_type():
|
|
|
|
model = resources[0].content_type.model_class()
|
|
|
|
model.add_to_class('resources', relation)
|