Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 3 | from core.models import PlCoreBase |
Tony Mack | 4f134e6 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 4 | from core.models import Site, SiteDeployment |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 5 | from core.models import Tag |
| 6 | from django.contrib.contenttypes import generic |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 7 | |
| 8 | # Create your models here. |
| 9 | |
| 10 | class Node(PlCoreBase): |
| 11 | name = models.CharField(max_length=200, unique=True, help_text="Name of the Node") |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 12 | site_deployment = models.ForeignKey(SiteDeployment, related_name='nodes') |
Tony Mack | 4f134e6 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 13 | site = models.ForeignKey(Site, null=True, blank=True, related_name='nodes') |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 14 | tags = generic.GenericRelation(Tag) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 15 | |
| 16 | def __unicode__(self): return u'%s' % (self.name) |
Sapan Bhatia | 690f803 | 2014-06-13 12:50:36 -0400 | [diff] [blame] | 17 | |
Tony Mack | 4f134e6 | 2015-01-14 20:58:38 -0500 | [diff] [blame] | 18 | def save(self, *args, **kwds): |
| 19 | if self.site is None and self.site_deployment is not None: |
| 20 | self.site = self.site_deployment.site |
| 21 | |
| 22 | super(Node, self).save(*args, **kwds) |