change the RAID model so that it uses django-nested-admin
This commit is contained in:
parent
4b1d1dace8
commit
e158cc7b36
|
@ -1,8 +1,10 @@
|
|||
from django.contrib import admin
|
||||
from guardian.admin import GuardedModelAdmin
|
||||
import nested_admin
|
||||
|
||||
from .models import (Backup, BackupMethod, TargetDevice, Device, RamType, Ram,
|
||||
DiskType, Owner, Disk, CpuArchitecture, CpuManufacturer,
|
||||
Cpu, OperatingSystem, RaidInComputer, Computer,
|
||||
Cpu, OperatingSystem, Computer, Raid,
|
||||
ComputerDiskRelation, DisksInRaid, RaidType,
|
||||
ComputerCpuRelation, ComputerSoftwareRelation,
|
||||
ComputerRamRelation, Warranty, WarrantyType, Customer,
|
||||
|
@ -105,14 +107,6 @@ class OperatingSystemAdmin(admin.ModelAdmin):
|
|||
return {}
|
||||
|
||||
|
||||
class RaidInComputerAdmin(admin.ModelAdmin):
|
||||
def get_model_perms(self, request):
|
||||
"""
|
||||
Return empty perms dict thus hiding the model from admin index.
|
||||
"""
|
||||
return {}
|
||||
|
||||
|
||||
class RamModuleAdmin(admin.ModelAdmin):
|
||||
def get_model_perms(self, request):
|
||||
"""
|
||||
|
@ -201,43 +195,50 @@ class DiskInRaidAdmin(admin.ModelAdmin):
|
|||
return {}
|
||||
|
||||
|
||||
class SoftwareInLine(admin.StackedInline):
|
||||
class SoftwareInLine(nested_admin.NestedStackedInline):
|
||||
model = ComputerSoftwareRelation
|
||||
extra = 0
|
||||
verbose_name_plural = 'Software'
|
||||
|
||||
|
||||
class RamInLine(admin.StackedInline):
|
||||
class RamInLine(nested_admin.NestedStackedInline):
|
||||
model = ComputerRamRelation
|
||||
extra = 0
|
||||
verbose_name_plural = 'RAM Modules'
|
||||
|
||||
|
||||
class DiskInLine(admin.StackedInline):
|
||||
class DiskInLine(nested_admin.NestedStackedInline):
|
||||
model = ComputerDiskRelation
|
||||
extra = 0
|
||||
verbose_name_plural = 'Disks'
|
||||
|
||||
|
||||
class CpusInLine(admin.StackedInline):
|
||||
class DisksInRaidInLine(nested_admin.NestedStackedInline):
|
||||
model = DisksInRaid
|
||||
extra = 0
|
||||
verbose_name_plural = 'Disks in RAID'
|
||||
|
||||
|
||||
class CpusInLine(nested_admin.NestedStackedInline):
|
||||
model = ComputerCpuRelation
|
||||
extra = 0
|
||||
verbose_name_plural = 'CPUs'
|
||||
|
||||
|
||||
class RaidInLine(admin.StackedInline):
|
||||
model = RaidInComputer
|
||||
class RaidInLine(nested_admin.NestedStackedInline):
|
||||
model = Raid
|
||||
extra = 0
|
||||
verbose_name_plural = 'RAID'
|
||||
inlines = (DisksInRaidInLine,)
|
||||
|
||||
|
||||
class DeviceInNetInline(admin.StackedInline):
|
||||
class DeviceInNetInline(nested_admin.NestedStackedInline):
|
||||
model = DeviceInNet
|
||||
extra = 0
|
||||
verbose_name_plural = 'Nets'
|
||||
|
||||
|
||||
class ComputerAdmin(admin.ModelAdmin):
|
||||
class ComputerAdmin(nested_admin.NestedModelAdmin):
|
||||
list_display = ('name', 'host')
|
||||
inlines = (SoftwareInLine, CpusInLine, RamInLine, DiskInLine, RaidInLine,
|
||||
DeviceInNetInline)
|
||||
|
@ -291,7 +292,6 @@ admin.site.register(DeviceInNet)
|
|||
admin.site.register(DeviceManufacturer, DeviceManufacturerAdmin)
|
||||
admin.site.register(Disk)
|
||||
admin.site.register(DiskType, DiskTypeAdmin)
|
||||
admin.site.register(DisksInRaid, DiskInRaidAdmin)
|
||||
admin.site.register(IpStatus, IpStatusAdmin)
|
||||
admin.site.register(Location)
|
||||
admin.site.register(MailAlias, MailAliasAdmin)
|
||||
|
@ -301,7 +301,6 @@ admin.site.register(Notification, NotificationAdmin)
|
|||
admin.site.register(NotificationType, NotificationTypeAdmin)
|
||||
admin.site.register(OperatingSystem, OperatingSystemAdmin)
|
||||
admin.site.register(Owner)
|
||||
admin.site.register(RaidInComputer, RaidInComputerAdmin)
|
||||
admin.site.register(RaidType, RaidTypeAdmin)
|
||||
admin.site.register(Ram, RamModuleAdmin)
|
||||
admin.site.register(RamType, RamTypeAdmin)
|
||||
|
|
|
@ -3,7 +3,7 @@ from .calendar import DayOfMonth, Month, Weekday
|
|||
from .category import Category
|
||||
from .companies import Company, Customer, DeviceManufacturer, Owner
|
||||
from .computer import (Computer, ComputerCpuRelation, ComputerDiskRelation,
|
||||
ComputerRamRelation, RaidInComputer,
|
||||
ComputerRamRelation,
|
||||
ComputerSoftwareRelation)
|
||||
from .cpu import CpuArchitecture, CpuManufacturer, Cpu
|
||||
from .devices import (DeviceCategory, Device, ConnectedDevice, DeviceInNet)
|
||||
|
@ -14,7 +14,7 @@ from .mailalias import MailAlias
|
|||
from .net import Net, IpStatus
|
||||
from .notification import Notification, NotificationType
|
||||
from .os import OperatingSystem
|
||||
from .raid import DisksInRaid, RaidType
|
||||
from .raid import DisksInRaid, RaidType, Raid
|
||||
from .ram import RamType, Ram
|
||||
from .software import SoftwareArchitecture, SoftwareCategory, Software
|
||||
from .time import HoursInDay, MinutesInHour
|
||||
|
|
|
@ -3,7 +3,6 @@ from .cpu import Cpu
|
|||
from .devices import ConnectedDevice
|
||||
from .disk import Disk
|
||||
from .os import OperatingSystem
|
||||
from .raid import RaidType, DisksInRaid
|
||||
from .ram import Ram
|
||||
from .software import Software, SoftwareArchitecture
|
||||
|
||||
|
@ -67,21 +66,6 @@ class ComputerDiskRelation(models.Model):
|
|||
verbose_name_plural = "Disks in Computer"
|
||||
|
||||
|
||||
class RaidInComputer(models.Model):
|
||||
disks = models.ForeignKey(DisksInRaid, models.SET_NULL, blank=True,
|
||||
null=True)
|
||||
usable_space = models.IntegerField(blank=True, null=True)
|
||||
raid_type = models.ForeignKey(RaidType, models.SET_NULL, blank=True,
|
||||
null=True)
|
||||
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.computer.name
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "RAIDs in Computer"
|
||||
|
||||
|
||||
class ComputerSoftwareRelation(models.Model):
|
||||
software = models.ForeignKey(Software, on_delete=models.CASCADE)
|
||||
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
||||
|
|
|
@ -1,12 +1,29 @@
|
|||
from django.db import models
|
||||
from .disk import Disk
|
||||
from .category import Category
|
||||
from .computer import Computer
|
||||
|
||||
|
||||
class RaidType(Category):
|
||||
pass
|
||||
|
||||
|
||||
class Raid(models.Model):
|
||||
usable_space = models.IntegerField(blank=True, null=True)
|
||||
raid_type = models.ForeignKey(RaidType, models.SET_NULL, blank=True,
|
||||
null=True)
|
||||
computer = models.ForeignKey(Computer, on_delete=models.CASCADE)
|
||||
|
||||
def __str__(self):
|
||||
return self.computer.name
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "RAIDs in Computer"
|
||||
|
||||
|
||||
class DisksInRaid(models.Model):
|
||||
disk = models.ForeignKey(Disk, on_delete=models.CASCADE)
|
||||
disk_amount = models.IntegerField()
|
||||
raid = models.ForeignKey(Raid, on_delete=models.CASCADE)
|
||||
|
||||
|
||||
|
|
|
@ -47,10 +47,10 @@ def test_computer_detail_view_ram_relation(create_admin_user):
|
|||
def test_computer_detail_view_raid_relation(create_admin_user):
|
||||
create_admin_user()
|
||||
computer = mixer.blend('inventory.Computer', customer=mixer.SELECT)
|
||||
raid = mixer.blend('inventory.RaidType')
|
||||
raid_type = mixer.blend('inventory.RaidType')
|
||||
disk = mixer.blend('inventory.Disk')
|
||||
raid = mixer.blend('inventory.Raid', computer=computer, raid_type=raid_type)
|
||||
disks = mixer.blend('inventory.DisksInRaid', raid=raid, disk=disk)
|
||||
mixer.blend('inventory.RaidInComputer', computer=computer, raid=disks)
|
||||
client = Client()
|
||||
client.login(username="novartis-admin", password="password")
|
||||
response = client.get('/computer/' + str(computer.id) + '/')
|
||||
|
|
|
@ -15,7 +15,7 @@ from .decorators import (computer_view_permission, customer_view_permission,
|
|||
net_view_permission)
|
||||
from .models import (Device, Computer, ComputerRamRelation,
|
||||
ComputerDiskRelation, ComputerCpuRelation,
|
||||
ComputerSoftwareRelation, Customer, Net, RaidInComputer,
|
||||
ComputerSoftwareRelation, Customer, Net, Raid,
|
||||
Backup, DeviceInNet)
|
||||
from .tables import (CustomersTable, ComputersTable, DevicesTable, NetsTable,
|
||||
BackupsTable, NetDetailTable, BackupDetailTable)
|
||||
|
@ -37,8 +37,8 @@ def computer_detail_view(request, pk):
|
|||
ram_list = ComputerRamRelation.objects.filter(computer=pk)
|
||||
cpu_list = ComputerCpuRelation.objects.filter(computer=pk)
|
||||
software_list = ComputerSoftwareRelation.objects.filter(computer=pk)
|
||||
raid_relations = RaidInComputer.objects.filter(computer=pk)
|
||||
raid_relations = RaidInComputer.objects.filter(computer=pk)
|
||||
raid_relations = Raid.objects.filter(computer=pk)
|
||||
raid_relations = Raid.objects.filter(computer=pk)
|
||||
backup_list = Backup.objects.filter(computer=pk)
|
||||
context = {'computer': computer,
|
||||
'disks_list': disks_list,
|
||||
|
|
|
@ -32,6 +32,7 @@ INSTALLED_APPS = [
|
|||
'guardian',
|
||||
'django_tables2',
|
||||
'django_filters',
|
||||
'nested_admin',
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
|
|
|
@ -20,4 +20,5 @@ from django.urls import path
|
|||
urlpatterns = [
|
||||
url(r'', include('inventory.urls')),
|
||||
path('admin/', admin.site.urls),
|
||||
url(r'^_nested_admin/', include('nested_admin.urls')),
|
||||
]
|
||||
|
|
|
@ -5,6 +5,7 @@ pytz
|
|||
django-guardian
|
||||
django-tables2
|
||||
django-filter
|
||||
django-nested-admin
|
||||
pytest
|
||||
pytest-django
|
||||
pytest-cov
|
||||
|
|
Loading…
Reference in New Issue