Rename model
This commit is contained in:
parent
02b1f890fd
commit
def755b714
@ -1,7 +1,7 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import Machine, MachineStatus, MachineNote
|
||||
from .models import Machine, MachineStatus, MachineReservation
|
||||
|
||||
|
||||
class MachineAdmin(admin.ModelAdmin):
|
||||
@ -13,10 +13,10 @@ class MachineStatusAdmin(admin.ModelAdmin):
|
||||
'last_updated', 'git_branch', 'git_version')
|
||||
|
||||
|
||||
class MachineNoteAdmin(admin.ModelAdmin):
|
||||
class MachineReservationAdmin(admin.ModelAdmin):
|
||||
list_display = ('machine', 'notes', 'user')
|
||||
|
||||
|
||||
admin.site.register(Machine, MachineAdmin)
|
||||
admin.site.register(MachineStatus, MachineStatusAdmin)
|
||||
admin.site.register(MachineNote, MachineNoteAdmin)
|
||||
admin.site.register(MachineReservation, MachineReservationAdmin)
|
||||
|
0
stagestatus/apps/machines/api/__init__.py
Normal file
0
stagestatus/apps/machines/api/__init__.py
Normal file
@ -3,5 +3,5 @@ from rest_framework import routers
|
||||
router = routers.SimpleRouter()
|
||||
|
||||
router.register('machine', vs.MachineViewSet)
|
||||
router.register('machine_note', vs.MachineNoteViewSet)
|
||||
router.register('machine_reservation', vs.MachineReservationViewSet)
|
||||
router.register('machine_status', vs.MachineStatusViewSet)
|
||||
|
@ -1,12 +1,12 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from machines.models import Machine, MachineNote, MachineStatus
|
||||
from machines.models import Machine, MachineReservation, MachineStatus
|
||||
|
||||
|
||||
class MachineNoteSerializer(serializers.ModelSerializer):
|
||||
class MachineReservationSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = MachineNote
|
||||
model = MachineReservation
|
||||
fields = (
|
||||
'machine',
|
||||
'user',
|
||||
@ -28,7 +28,7 @@ class MachineStatusSerializer(serializers.ModelSerializer):
|
||||
|
||||
|
||||
class MachineSerializer(serializers.ModelSerializer):
|
||||
machine_note = MachineNoteSerializer(read_only=True)
|
||||
machine_reservation = MachineReservationSerializer(read_only=True)
|
||||
machine_status = MachineStatusSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
@ -36,6 +36,6 @@ class MachineSerializer(serializers.ModelSerializer):
|
||||
fields = (
|
||||
'hostname',
|
||||
'db_server',
|
||||
'machine_note',
|
||||
'machine_reservation',
|
||||
'machine_status',
|
||||
)
|
||||
|
@ -3,13 +3,13 @@ from rest_framework import viewsets
|
||||
|
||||
from machines.api.serializers import (
|
||||
MachineSerializer,
|
||||
MachineNoteSerializer,
|
||||
MachineReservationSerializer,
|
||||
MachineStatusSerializer
|
||||
)
|
||||
|
||||
from machines.api.models import (
|
||||
from machines.models import (
|
||||
Machine,
|
||||
MachineNote,
|
||||
MachineReservation,
|
||||
MachineStatus
|
||||
)
|
||||
|
||||
@ -20,10 +20,10 @@ class MachineViewSet(mixins.ListModelMixin,
|
||||
queryset = Machine.objects.all()
|
||||
|
||||
|
||||
class MachineNoteViewSet(mixins.ListModelMixin,
|
||||
viewsets.GenericViewSet):
|
||||
serializer_class = MachineNoteSerializer
|
||||
queryset = MachineNote.objects.all()
|
||||
class MachineReservationViewSet(mixins.ListModelMixin,
|
||||
viewsets.GenericViewSet):
|
||||
serializer_class = MachineReservationSerializer
|
||||
queryset = MachineReservation.objects.all()
|
||||
|
||||
|
||||
class MachineStatusViewSet(mixins.ListModelMixin,
|
||||
|
@ -0,0 +1,19 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.6 on 2017-04-01 20:27
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('machines', '0002_auto_20170401_1258'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RenameModel(
|
||||
old_name='MachineNote',
|
||||
new_name='MachineReservation',
|
||||
),
|
||||
]
|
@ -20,8 +20,8 @@ class Machine(models.Model):
|
||||
|
||||
def is_reserved(self):
|
||||
try:
|
||||
return bool(self.machinenote)
|
||||
except MachineNote.DoesNotExist:
|
||||
return bool(self.machinereservation)
|
||||
except MachineReservation.DoesNotExist:
|
||||
return False
|
||||
|
||||
def __unicode__(self):
|
||||
@ -52,7 +52,7 @@ class MachineStatus(models.Model):
|
||||
verbose_name_plural = 'Machine Statuses'
|
||||
|
||||
|
||||
class MachineNote(models.Model):
|
||||
class MachineReservation(models.Model):
|
||||
"""
|
||||
Notes on the machine as well as who has it checked out.
|
||||
"""
|
||||
|
41
stagestatus/apps/machines/serializers.py
Normal file
41
stagestatus/apps/machines/serializers.py
Normal file
@ -0,0 +1,41 @@
|
||||
from rest_framework import serializers
|
||||
|
||||
from machines.models import Machine, MachineReservation, MachineStatus
|
||||
|
||||
|
||||
class MachineReservationSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = MachineReservation
|
||||
fields = (
|
||||
'machine',
|
||||
'user',
|
||||
'notes',
|
||||
)
|
||||
|
||||
|
||||
class MachineStatusSerializer(serializers.ModelSerializer):
|
||||
|
||||
class Meta:
|
||||
model = MachineStatus
|
||||
fields = (
|
||||
'machine',
|
||||
'git_branch',
|
||||
'git_version',
|
||||
'last_db_refresh',
|
||||
'last_updated'
|
||||
)
|
||||
|
||||
|
||||
class MachineSerializer(serializers.ModelSerializer):
|
||||
machine_reservation = MachineReservationSerializer(read_only=True)
|
||||
machine_status = MachineStatusSerializer(read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Machine
|
||||
fields = (
|
||||
'hostname',
|
||||
'db_server',
|
||||
'machine_reservation',
|
||||
'machine_status',
|
||||
)
|
@ -6,7 +6,7 @@ from model_mommy import mommy
|
||||
|
||||
# Models
|
||||
from django.contrib.auth.models import User
|
||||
from machines.models import Machine, MachineStatus, MachineNote
|
||||
from machines.models import Machine, MachineStatus, MachineReservation
|
||||
|
||||
|
||||
class ModelsTest(TestCase):
|
||||
@ -17,14 +17,14 @@ class ModelsTest(TestCase):
|
||||
self.machine_status = mommy.make(MachineStatus,
|
||||
machine=self.machine
|
||||
)
|
||||
self.machine_note = mommy.make(MachineNote,
|
||||
user=self.user,
|
||||
machine=self.machine
|
||||
)
|
||||
self.machine_reservation = mommy.make(MachineReservation,
|
||||
user=self.user,
|
||||
machine=self.machine
|
||||
)
|
||||
|
||||
def test_mommy(self):
|
||||
""" General assertions to test models """
|
||||
self.assertEqual(self.machine_status.machine, self.machine)
|
||||
self.assertEqual(self.machine_note.machine, self.machine)
|
||||
self.assertEqual(self.machine_reservation.machine, self.machine)
|
||||
self.assertEqual(self.machine_status.machine,
|
||||
self.machine_note.machine)
|
||||
self.machine_reservation.machine)
|
||||
|
@ -7,7 +7,8 @@ from rest_framework.renderers import JSONRenderer
|
||||
|
||||
# Models
|
||||
from django.contrib.auth.models import User
|
||||
from machines.models import Machine, MachineStatus, MachineNote
|
||||
from machines.models import Machine, MachineStatus, MachineReservation
|
||||
|
||||
|
||||
from machines.api.serializers import MachineSerializer
|
||||
|
||||
@ -20,10 +21,10 @@ class SerializerTest(TestCase):
|
||||
self.machine_status = mommy.make(MachineStatus,
|
||||
machine=self.machine
|
||||
)
|
||||
self.machine_note = mommy.make(MachineNote,
|
||||
user=self.user,
|
||||
machine=self.machine
|
||||
)
|
||||
self.machine_reservation = mommy.make(MachineReservation,
|
||||
user=self.user,
|
||||
machine=self.machine
|
||||
)
|
||||
|
||||
def test_serializer(self):
|
||||
"""
|
||||
|
@ -1,6 +1,6 @@
|
||||
from machines.views import MachineList, MachineDetail
|
||||
from django.conf.urls import url, include
|
||||
from machines.routers import router
|
||||
from machines.api.routers import router
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^api/', include(router.urls)),
|
||||
|
@ -5,10 +5,10 @@
|
||||
<li>Git Branch: {{ machine.machinestatus.git_branch }}</li>
|
||||
<li>Git Version: {{ machine.machinestatus.git_version }}</li>
|
||||
|
||||
{% if machine.machinenote %}
|
||||
<li>User: {{ machine.machinenote.user }}</li>
|
||||
{% if machine.machinereservation %}
|
||||
<li>User: {{ machine.machinereservation.user }}</li>
|
||||
<li>Notes: <br>
|
||||
<span>{{ machine.machinenote.notes|linebreaksbr }}</span>
|
||||
<span>{{ machine.machinereservation.notes|linebreaksbr }}</span>
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
|
Loading…
Reference in New Issue
Block a user