Coverage for src/backend/InvenTree/machine/admin.py: 68%
17 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Django admin interface for the machine app."""
3from django.contrib import admin
5from machine import models
8class MachineSettingInline(admin.TabularInline):
9 """Inline admin class for MachineSetting."""
11 model = models.MachineSetting
13 read_only_fields = ['key', 'config_type']
15 def has_add_permission(self, request, obj):
16 """The machine settings should not be meddled with manually."""
17 return False
20@admin.register(models.MachineConfig)
21class MachineConfigAdmin(admin.ModelAdmin):
22 """Custom admin with restricted id fields."""
24 list_filter = ['active']
25 list_display = [
26 'name',
27 'machine_type',
28 'driver',
29 'initialized',
30 'active',
31 'no_errors',
32 'get_machine_status',
33 ]
34 readonly_fields = [
35 'initialized',
36 'is_driver_available',
37 'get_admin_errors',
38 'get_machine_status',
39 ]
40 inlines = [MachineSettingInline]
42 def get_readonly_fields(self, request, obj):
43 """If update, don't allow changes on machine_type and driver."""
44 if obj is not None:
45 return ['machine_type', 'driver', *self.readonly_fields]
47 return self.readonly_fields