blob: 7818c32bff88ea92a8143b0a893fc2bf69c2e5aa [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):
27 if user.is_admin:
28 return True
29 return False
30
Tony Mack5b061472014-02-04 07:57:10 -050031 @staticmethod
32 def select_by_user(user):
33 return Tag.objects.all()