diff --git a/stagestatus/apps/machines/api/routers.py b/stagestatus/apps/machines/api/routers.py index 7ec1dba..0a9bfdf 100644 --- a/stagestatus/apps/machines/api/routers.py +++ b/stagestatus/apps/machines/api/routers.py @@ -3,5 +3,5 @@ from rest_framework import routers router = routers.SimpleRouter() router.register('machine', vs.MachineViewSet) -router.register('machine_reservation', vs.MachineReservationViewSet) -router.register('machine_status', vs.MachineStatusViewSet) +router.register('reservation', vs.MachineReservationViewSet) +router.register('status', vs.MachineStatusViewSet) diff --git a/stagestatus/apps/machines/api/serializers.py b/stagestatus/apps/machines/api/serializers.py index e7602cc..d66d1ea 100644 --- a/stagestatus/apps/machines/api/serializers.py +++ b/stagestatus/apps/machines/api/serializers.py @@ -28,14 +28,17 @@ class MachineStatusSerializer(serializers.ModelSerializer): class MachineSerializer(serializers.ModelSerializer): - machine_reservation = MachineReservationSerializer(read_only=True) - machine_status = MachineStatusSerializer(read_only=True) + is_reserved = serializers.SerializerMethodField() + + def get_is_reserved(self, machine): + return machine.is_reserved() class Meta: model = Machine fields = ( 'hostname', 'db_server', - 'machine_reservation', - 'machine_status', + 'reservation', + 'status', + 'is_reserved' ) diff --git a/stagestatus/apps/machines/migrations/0004_auto_20170401_1538.py b/stagestatus/apps/machines/migrations/0004_auto_20170401_1538.py new file mode 100644 index 0000000..b5b3230 --- /dev/null +++ b/stagestatus/apps/machines/migrations/0004_auto_20170401_1538.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.6 on 2017-04-01 20:38 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('machines', '0003_rename_machinenote_machinereservation'), + ] + + operations = [ + migrations.AlterField( + model_name='machinereservation', + name='machine', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='reservation', to='machines.Machine'), + ), + migrations.AlterField( + model_name='machinestatus', + name='machine', + field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='status', to='machines.Machine'), + ), + ] diff --git a/stagestatus/apps/machines/models.py b/stagestatus/apps/machines/models.py index 7989f8f..60e521d 100644 --- a/stagestatus/apps/machines/models.py +++ b/stagestatus/apps/machines/models.py @@ -20,7 +20,7 @@ class Machine(models.Model): def is_reserved(self): try: - return bool(self.machinereservation) + return bool(self.reservation) except MachineReservation.DoesNotExist: return False @@ -34,7 +34,8 @@ class MachineStatus(models.Model): This data will change every time a machine is checked out, or nightly refreshes, or anything. """ - machine = models.OneToOneField('Machine') + machine = models.OneToOneField('Machine', + related_name='status') git_branch = models.CharField( max_length=256, @@ -56,7 +57,8 @@ class MachineReservation(models.Model): """ Notes on the machine as well as who has it checked out. """ - machine = models.OneToOneField('Machine') + machine = models.OneToOneField('Machine', + related_name='reservation') notes = models.TextField( help_text='Reason you are checking out the server.') diff --git a/stagestatus/templates/machines/machine_detail.html b/stagestatus/templates/machines/machine_detail.html index c40fd89..c8c686d 100644 --- a/stagestatus/templates/machines/machine_detail.html +++ b/stagestatus/templates/machines/machine_detail.html @@ -1,14 +1,14 @@ {{machine.hostname}}