Source code for sandglass.models.tag
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django_extensions.db.models import TimeStampedModel
TAG_TYPE_ACTIVITY = 'activity'
TAG_TYPE_ACCOUNTING = 'accounting'
TAG_TYPE_TIME = 'time'
TAG_TYPES = (
(TAG_TYPE_ACTIVITY, _(u"activity")),
(TAG_TYPE_ACCOUNTING, _(u"accounting")),
(TAG_TYPE_TIME, _(u"time")),
)
[docs]class Tag(TimeStampedModel):
"""Model definition for tags.
Tags are added by users with right permissions. Normal users can't
create new tags, instead of that they can create a tag alias.
A tag alias can be used to have custom tags by user. Field `alias_of`
and `owner` are initialized when a Tag instance is an alias.
"""
name = models.CharField(
verbose_name=_(u"name"), max_length=255, db_index=True)
acronym = models.CharField(
verbose_name=_(u"acronym"), max_length=10, db_index=True,
blank=True, null=True)
description = models.TextField(
verbose_name=_(u"description"), blank=True, null=True)
tag_type = models.CharField(
verbose_name=_(u"tag type"), choices=TAG_TYPES,
max_length=20, default=TAG_TYPE_ACTIVITY, db_index=True)
hourly_price = models.DecimalField(
verbose_name=_(u"hourly price"),
max_digits=6, decimal_places=2,
blank=True, null=True, validators=[MinValueValidator(0)])
alias_of = models.ForeignKey(
'self', verbose_name=_(u"aliased tag"), blank=True, null=True)
owner = models.ForeignKey(
User, verbose_name=_(u"tag owner"), blank=True, null=True)
class Meta:
app_label = 'sandglass'
__all__ = ('Tag',)