Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
| 3 | from core.models import PlCoreBase |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 4 | from core.models import Service |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 5 | from django.contrib.contenttypes.models import ContentType |
| 6 | from django.contrib.contenttypes import generic |
| 7 | |
| 8 | # Create your models here. |
| 9 | |
| 10 | class Tag(PlCoreBase): |
| 11 | |
Siobhan Tully | ce652d0 | 2013-10-08 21:52:35 -0400 | [diff] [blame] | 12 | service = models.ForeignKey(Service, related_name='tags', help_text="The Service this Tag is associated with") |
Siobhan Tully | d351575 | 2013-06-21 16:34:53 -0400 | [diff] [blame] | 13 | |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 14 | 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 Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 25 | |
| 26 | def can_update(self, user): |
| 27 | if user.is_admin: |
| 28 | return True |
| 29 | return False |
| 30 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 31 | @staticmethod |
| 32 | def select_by_user(user): |
| 33 | return Tag.objects.all() |