diff options
author | SVN-Git Migration <python-modules-team@lists.alioth.debian.org> | 2015-10-08 11:51:45 -0700 |
---|---|---|
committer | SVN-Git Migration <python-modules-team@lists.alioth.debian.org> | 2015-10-08 11:51:45 -0700 |
commit | 3b9f21a55fed735652716e63fedabad87899be81 (patch) | |
tree | b6f57d335a1be88466d7780a6bb3101e81df2dde /tagging/models.py | |
parent | 2228968f3d51a3d686adb2839bf43e018432f941 (diff) | |
download | python-django-tagging-3b9f21a55fed735652716e63fedabad87899be81.tar python-django-tagging-3b9f21a55fed735652716e63fedabad87899be81.tar.gz |
Imported Upstream version 0.2.1upstream/0.2.1
Diffstat (limited to 'tagging/models.py')
-rw-r--r-- | tagging/models.py | 105 |
1 files changed, 52 insertions, 53 deletions
diff --git a/tagging/models.py b/tagging/models.py index 199e5eb..f81c896 100644 --- a/tagging/models.py +++ b/tagging/models.py @@ -1,53 +1,52 @@ -""" -Models for generic tagging. -""" -from django.db import models -from django.contrib.contenttypes import generic -from django.contrib.contenttypes.models import ContentType - -from tagging.managers import TagManager, TaggedItemManager -from tagging.validators import isTag - -class Tag(models.Model): - """ - A basic tag. - """ - name = models.CharField(max_length=50, unique=True, db_index=True, validator_list=[isTag]) - - objects = TagManager() - - class Meta: - db_table = 'tag' - verbose_name = 'Tag' - verbose_name_plural = 'Tags' - ordering = ('name',) - - class Admin: - pass - - def __unicode__(self): - return self.name - -class TaggedItem(models.Model): - """ - Holds the relationship between a tag and the item being tagged. - """ - tag = models.ForeignKey(Tag, related_name='items') - content_type = models.ForeignKey(ContentType) - object_id = models.PositiveIntegerField() - object = generic.GenericForeignKey('content_type', 'object_id') - - objects = TaggedItemManager() - - class Meta: - db_table = 'tagged_item' - verbose_name = 'Tagged Item' - verbose_name_plural = 'Tagged Items' - # Enforce unique tag association per object - unique_together = (('tag', 'content_type', 'object_id'),) - - class Admin: - pass - - def __unicode__(self): - return u'%s [%s]' % (self.object, self.tag) +"""
+Models for generic tagging.
+"""
+from django.db import models
+from django.contrib.contenttypes import generic
+from django.contrib.contenttypes.models import ContentType
+from django.utils.translation import ugettext_lazy as _
+
+from tagging.managers import TagManager, TaggedItemManager
+from tagging.validators import isTag
+
+class Tag(models.Model):
+ """
+ A tag.
+ """
+ name = models.CharField(_('name'), max_length=50, unique=True, db_index=True, validator_list=[isTag])
+
+ objects = TagManager()
+
+ class Meta:
+ ordering = ('name',)
+ verbose_name = _('tag')
+ verbose_name_plural = _('tags')
+
+ class Admin:
+ pass
+
+ def __unicode__(self):
+ return self.name
+
+class TaggedItem(models.Model):
+ """
+ Holds the relationship between a tag and the item being tagged.
+ """
+ tag = models.ForeignKey(Tag, verbose_name=_('tag'), related_name='items')
+ content_type = models.ForeignKey(ContentType, verbose_name=_('content type'))
+ object_id = models.PositiveIntegerField(_('object id'), db_index=True)
+ object = generic.GenericForeignKey('content_type', 'object_id')
+
+ objects = TaggedItemManager()
+
+ class Meta:
+ # Enforce unique tag association per object
+ unique_together = (('tag', 'content_type', 'object_id'),)
+ verbose_name = _('tagged item')
+ verbose_name_plural = _('tagged items')
+
+ class Admin:
+ pass
+
+ def __unicode__(self):
+ return u'%s [%s]' % (self.object, self.tag)
|