-
-
-##########
-# Models #
-##########
-
-class TagMeta(ModelBase):
- """Metaclass for tag models (models inheriting from TagBase)."""
- def __new__(mcs, name, bases, attrs):
- model = super(TagMeta, mcs).__new__(mcs, name, bases, attrs)
- if not model._meta.abstract:
- # Register custom managers for concrete models
- TagManager(model.intermediary_table_model).contribute_to_class(model, 'objects')
- TaggedItemManager(model).contribute_to_class(model.intermediary_table_model, 'objects')
- return model
-
-
-class TagBase(models.Model):
- """Abstract class to be inherited by model classes."""
- __metaclass__ = TagMeta
-
- class Meta:
- abstract = True
-
- @staticmethod
- def get_tag_list(tag_list):
- """
- Utility function for accepting tag input in a flexible manner.
-
- You should probably override this method in your subclass.
- """
- if isinstance(tag_list, TagBase):
- return [tag_list]
- else:
- return tag_list