source: django_apps/foobar/models.py@ 387

Last change on this file since 387 was 302, checked in by Rick van der Zwet, 14 years ago

Some awefull hack to get a 2x2 single value table displayed for easy editing...

File size: 978 bytes
Line 
1from django.db import models
2
3# Create your models here.
4class Role(models.Model):
5 name = models.CharField(max_length=50)
6 def __unicode__(self):
7 return self.name
8
9 def save(self, *args, **kwargs):
10 is_new = self.id is None
11 super(Role, self).save(*args, **kwargs)
12 if is_new:
13 for service in Service.objects.all():
14 alert = Alert(role=self, service=service, enable=False)
15 alert.save()
16
17class Service(models.Model):
18 name = models.CharField(max_length=50)
19 def __unicode__(self):
20 return self.name
21
22 def save(self, *args, **kwargs):
23 is_new = self.id is None
24 super(Service, self).save(*args, **kwargs)
25 if is_new:
26 for role in Role.objects.all():
27 alert = Alert(role=role, service=self, enable=False)
28 alert.save()
29
30class Alert(models.Model):
31 enable = models.BooleanField()
32 role = models.ForeignKey(Role)
33 service = models.ForeignKey(Service)
34 class Meta:
35 unique_together = (('role', 'service'))
Note: See TracBrowser for help on using the repository browser.