Commit 6ecb2371 authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Rename new deployment models

parent 9d60ce0b
......@@ -6,6 +6,8 @@ from django.db import models
from django.db.models import Q
from django_mysql.models import JSONField
from polymorphic.models import PolymorphicModel
from rest_framework import serializers
from rest_polymorphic.serializers import PolymorphicSerializer
from .user_models import User
......@@ -25,7 +27,8 @@ def questionnaire_default():
def credential_default():
return {}
class Site(models.Model):
class NSite(models.Model):
name = models.CharField(
max_length=150,
unique=True,
......@@ -43,7 +46,7 @@ class Site(models.Model):
)
class Service(PolymorphicModel):
class NService(PolymorphicModel):
name = models.CharField(
max_length=150,
unique=True,
......@@ -53,18 +56,18 @@ class Service(PolymorphicModel):
blank=True,
)
site = models.ForeignKey(
Site,
NSite,
related_name='services',
on_delete=models.CASCADE,
)
class SimpleService(Service):
class SimpleService(NService):
groups = models.ManyToManyField(
Group,
related_name='services',
)
class GroupService(Service):
class GroupService(NService):
groups = models.ForeignKey(
Group,
related_name='services',
......@@ -72,7 +75,7 @@ class GroupService(Service):
)
class Deployment(PolymorphicModel):
class NDeployment(PolymorphicModel):
user = models.ForeignKey(
User,
related_name='deployments',
......@@ -113,14 +116,14 @@ class Deployment(PolymorphicModel):
else:
raise ValueError('get_deployment needs either a service or a group')
class ServiceDeployment(Deployment):
class ServiceDeployment(NDeployment):
service = models.ForeignKey(
Service,
NService,
related_name='service_deployments',
on_delete=models.CASCADE,
)
class GroupDeployment(Deployment):
class GroupDeployment(NDeployment):
group = models.ForeignKey(
Group,
related_name='group_deployments',
......@@ -128,9 +131,9 @@ class GroupDeployment(Deployment):
)
class DeploymentStateItem(PolymorphicModel):
class NDeploymentStateItem(PolymorphicModel):
site = models.ForeignKey(
Site,
NSite,
related_name='deployment_state_items',
on_delete=models.CASCADE,
)
......@@ -159,7 +162,7 @@ class DeploymentStateItem(PolymorphicModel):
blank=True,
)
class GroupDeploymentStateItem(DeploymentStateItem):
class GroupDeploymentStateItem(NDeploymentStateItem):
parent = models.ForeignKey(
GroupDeployment,
related_name='group_deployment_state_items',
......@@ -170,3 +173,40 @@ class GroupDeploymentStateItem(DeploymentStateItem):
related_name='group_deployment_state_items',
on_delete=models.CASCADE,
)
# serializers
class GroupSerializer(serializers.ModelSerializer):
class Meta:
model = Group
fields = ('name',)
class ServiceSerializer(serializers.ModelSerializer):
class Meta:
model = NService
fields = ('name', 'description', 'site',)
class SimpleServiceSerializer(serializers.ModelSerializer):
groups = GroupSerializer(many=True)
class Meta:
model = SimpleService
fields = ('name', 'description', 'site', 'groups',)
class GroupServiceSerializer(serializers.ModelSerializer):
group = GroupSerializer()
class Meta:
model = SimpleService
fields = ('name', 'description', 'site', 'group',)
class GenericServiceSerializer(PolymorphicSerializer):
mode_serializer_mapping = {
NService: ServiceSerializer,
SimpleService: SimpleServiceSerializer,
GroupService: GroupServiceSerializer,
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment