# 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
    def __str__(self):
        return self.name

    class Meta:
        db_table = 'wq_identifier'
        ordering = WQ_IDENTIFIER_ORDER
        abstract = not INSTALLED


class IdentifiedModelManager(NaturalKeyModelManager):
    def get_by_identifier(self, identifier, auto_create=False):
        searches = [
            {'slug': identifier},
            {'name': identifier},
            {'identifiers__slug': identifier},
            {'identifiers__name': identifier},
        ]

        obj = None
        for search in searches:
            try:
                obj = self.get(**search)
                break
            except (ValueError, self.model.DoesNotExist):
                pass

        if obj is None:
            if auto_create:
                obj = self.create_by_natural_key(identifier)
            else:

# 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

    def __str__(self):
        return self.name

    class Meta:
        db_table = 'wq_identifier'
        ordering = WQ_IDENTIFIER_ORDER
        abstract = not INSTALLED


class IdentifiedModelManager(NaturalKeyModelManager):
    def get_by_identifier(self, identifier, auto_create=False):
        searches = [
            {'slug': identifier},
            {'name': identifier},
            {'identifiers__slug': identifier},
            {'identifiers__name': identifier},
        ]

        obj = None
        for search in searches:
            try:
                obj = self.get(**search)
                break
            except (ValueError, self.model.DoesNotExist):
                pass

        if obj is None:
            if auto_create:
                obj = self.create_by_natural_key(identifier)
            else:

                name = self.model._meta.object_name