blob: b1e510a3e08a9a77088e4cb63742e318186020d2 [file] [log] [blame]
Siobhan Tullyde5450d2013-06-21 11:35:33 -04001import os
2from django.db import models
3from core.models import PlCoreBase
Siobhan Tullyce652d02013-10-08 21:52:35 -04004from core.models import Service
Siobhan Tullyde5450d2013-06-21 11:35:33 -04005from django.contrib.contenttypes.models import ContentType
6from django.contrib.contenttypes import generic
7
8# Create your models here.
9
10class Tag(PlCoreBase):
11
Siobhan Tullyce652d02013-10-08 21:52:35 -040012 service = models.ForeignKey(Service, related_name='tags', help_text="The Service this Tag is associated with")
Siobhan Tullyd3515752013-06-21 16:34:53 -040013
Siobhan Tullyde5450d2013-06-21 11:35:33 -040014 name = models.SlugField(help_text="The name of this tag", max_length=128)
15 value = models.CharField(help_text="The value of this tag", max_length=1024)
16
17 # The required fields to do a ObjectType lookup, and object_id assignment
18 content_type = models.ForeignKey(ContentType)
19 object_id = models.PositiveIntegerField()
20 content_object = generic.GenericForeignKey('content_type', 'object_id')
21
22 def __unicode__(self):
23 return self.name
24
Tony Mack5b061472014-02-04 07:57:10 -050025
26 def can_update(self, user):
Tony Mack5ff90fc2015-02-08 21:38:41 -050027 return user.can_update_root()
Tony Mack5b061472014-02-04 07:57:10 -050028
Tony Mack5b061472014-02-04 07:57:10 -050029 @staticmethod
30 def select_by_user(user):
31 return Tag.objects.all()