# Path: patterns/base/models.py
# class LabelModel(models.Model):
#     wq_label_template = "{{name}}"
# 
#     def __str__(self):
#         return pystache.render(self.wq_label_template, self)
# 
#     class Meta:
#         abstract = True


from django.db import models, connections
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import (
    GenericForeignKey, GenericRelation
)
from natural_keys.models import NaturalKeyModelManager, NaturalKeyModel
from ..base.models import LabelModel
from django.template.defaultfilters import slugify
from django.conf import settings
    identifiers = GenericRelation(Identifier)
    objects = IdentifiedModelManager()

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = find_unique_slug(self.name, type(self).objects)
        if not self.name:
            self.name = self.slug
        super(IdentifiedModel, self).save()
        ident, is_new = self.identifiers.get_or_create(
            is_primary=True,
            defaults={
                'name': self.name,
                'slug': self.slug,
            }
        )
        if not is_new and (ident.name != self.name or ident.slug != self.slug):
            ident.name = self.name
            ident.slug = self.slug
            ident.save()

    @property
    def primary_identifier(self):
        return self.identifiers.filter(is_primary=True).first()

    class Meta:
        ordering = ['name']
        abstract = True



# Path: patterns/base/models.py
# class LabelModel(models.Model):
#     wq_label_template = "{{name}}"
# 
#     def __str__(self):
#         return pystache.render(self.wq_label_template, self)
# 
#     class Meta:
#         abstract = True


# Path: patterns/identify/models.py
from django.db import models, connections
from django.contrib.contenttypes.models import ContentType
from django.contrib.contenttypes.fields import (
    GenericForeignKey, GenericRelation
)
from natural_keys.models import NaturalKeyModelManager, NaturalKeyModel
from ..base.models import LabelModel
from django.template.defaultfilters import slugify
from django.conf import settings

    identifiers = GenericRelation(Identifier)
    objects = IdentifiedModelManager()

    def save(self, *args, **kwargs):
        if not self.slug:
            self.slug = find_unique_slug(self.name, type(self).objects)
        if not self.name:
            self.name = self.slug
        super(IdentifiedModel, self).save()
        ident, is_new = self.identifiers.get_or_create(
            is_primary=True,
            defaults={
                'name': self.name,
                'slug': self.slug,
            }
        )
        if not is_new and (ident.name != self.name or ident.slug != self.slug):
            ident.name = self.name
            ident.slug = self.slug
            ident.save()

    @property
    def primary_identifier(self):
        return self.identifiers.filter(is_primary=True).first()

    class Meta:
        ordering = ['name']
        abstract = True



class Authority(LabelModel):