rename related_names on one to one relationships
This commit is contained in:
parent
23d0cecb4a
commit
ee67c0f0a8
@ -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)
|
||||
|
@ -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'
|
||||
)
|
||||
|
@ -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'),
|
||||
),
|
||||
]
|
@ -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.')
|
||||
|
@ -1,14 +1,14 @@
|
||||
<span>{{machine.hostname}}</span>
|
||||
<ul>
|
||||
<li>DB Server: {{ machine.db_server }}</li>
|
||||
<li>DB Refresh: {{machine.machinestatus.last_db_refresh }}</li>
|
||||
<li>Git Branch: {{ machine.machinestatus.git_branch }}</li>
|
||||
<li>Git Version: {{ machine.machinestatus.git_version }}</li>
|
||||
<li>DB Refresh: {{machine.status.last_db_refresh }}</li>
|
||||
<li>Git Branch: {{ machine.status.git_branch }}</li>
|
||||
<li>Git Version: {{ machine.status.git_version }}</li>
|
||||
|
||||
{% if machine.machinereservation %}
|
||||
<li>User: {{ machine.machinereservation.user }}</li>
|
||||
{% if machine.reservation %}
|
||||
<li>User: {{ machine.reservation.user }}</li>
|
||||
<li>Notes: <br>
|
||||
<span>{{ machine.machinereservation.notes|linebreaksbr }}</span>
|
||||
<span>{{ machine.reservation.notes|linebreaksbr }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user