blob: 5d3e258fd4b4ac41f7a18e6de3e867700f13beb4 [file] [log] [blame]
Scott Baker619de672016-06-20 12:49:38 -07001# models.py - ExampleService Models
2
3from core.models import Service, TenantWithContainer
4from django.db import models, transaction
5
6SERVICE_NAME = 'exampleservice'
7SERVICE_NAME_VERBOSE = 'Example Service'
8SERVICE_NAME_VERBOSE_PLURAL = 'Example Services'
9TENANT_NAME_VERBOSE = 'Example Tenant'
10TENANT_NAME_VERBOSE_PLURAL = 'Example Tenants'
11
12class ExampleService(Service):
13
14 KIND = SERVICE_NAME
15
16 class Meta:
17 app_label = SERVICE_NAME
18 verbose_name = SERVICE_NAME_VERBOSE
19
20 service_message = models.CharField(max_length=254, help_text="Service Message to Display")
21
22class ExampleTenant(TenantWithContainer):
23
24 KIND = SERVICE_NAME
25
26 class Meta:
27 verbose_name = TENANT_NAME_VERBOSE
28
29 tenant_message = models.CharField(max_length=254, help_text="Tenant Message to Display")
30
31 def __init__(self, *args, **kwargs):
32 exampleservice = ExampleService.get_service_objects().all()
33 if exampleservice:
34 self._meta.get_field('provider_service').default = exampleservice[0].id
35 super(ExampleTenant, self).__init__(*args, **kwargs)
36
37 def save(self, *args, **kwargs):
38 super(ExampleTenant, self).save(*args, **kwargs)
39 model_policy_exampletenant(self.pk)
40
41 def delete(self, *args, **kwargs):
42 self.cleanup_container()
43 super(ExampleTenant, self).delete(*args, **kwargs)
44
45
46def model_policy_exampletenant(pk):
47 with transaction.atomic():
48 tenant = ExampleTenant.objects.select_for_update().filter(pk=pk)
49 if not tenant:
50 return
51 tenant = tenant[0]
52 tenant.manage_container()
53