Files
Webanwendung-Netzwerk-Planer/inventar/admin.py
T
H4nSoloandClaude Opus 5.5 c1766cd8ca Phase 1 abgeschlossen: Art DSL, Host-IP an Bridge, Port 8001
- Schnittstellen-Art DSL: nur an Routern, ohne Bridge, Verbindung und IP
- IP-Adresse kann an einer Bridge liegen (Host-IP), alternativ zur Schnittstelle
- Admin: IP-Inline an Bridge und Schnittstelle inkl. Netz-Feld
- Lokaler Port 8001 (8000 durch Portainer belegt)
- README v0.4: offene Punkte 5 (teilweise) und 6 geklärt, Kapitel 10 aktualisiert
- 49 Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 13:24:35 +01:00

129 lines
4.2 KiB
Python

"""Django-Admin für Phase 1. Ab Phase 2 ersetzen eigene Formulare den Admin."""
from django.contrib import admin
from .forms import GeprueftesModelForm
from .models import SSID, Bridge, Geraet, IPAdresse, Netz, Schnittstelle, Standort, Verbindung
class SchnittstelleInline(admin.TabularInline):
form = GeprueftesModelForm
model = Schnittstelle
fk_name = "geraet"
extra = 0
fields = ["name", "art", "mac", "bridge", "vlan_tag", "durchgereicht_an", "ssid"]
show_change_link = True
class BridgeInline(admin.TabularInline):
form = GeprueftesModelForm
model = Bridge
extra = 0
fields = ["name", "vlan_aware", "notizen"]
class GastInline(admin.TabularInline):
model = Geraet
fk_name = "host"
extra = 0
fields = ["art", "proxmox_id", "name", "slug", "status"]
readonly_fields = fields
show_change_link = True
can_delete = False
verbose_name = "Gast"
verbose_name_plural = "Gäste"
def has_add_permission(self, request, obj=None):
return False
class IPAdresseInline(admin.TabularInline):
form = GeprueftesModelForm
model = IPAdresse
extra = 0
fields = ["adresse", "netz", "schnittstelle", "bridge", "art", "notiz"]
autocomplete_fields = ["schnittstelle"]
class IPAdresseImNetzInline(IPAdresseInline):
fields = ["adresse", "schnittstelle", "bridge", "art", "notiz"]
@admin.register(Standort)
class StandortAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["name", "slug"]
prepopulated_fields = {"slug": ["name"]}
@admin.register(Geraet)
class GeraetAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["__str__", "slug", "art", "typ", "rolle", "host", "standort", "status"]
list_filter = ["art", "typ", "status", "standort", "host"]
search_fields = ["name", "slug", "hersteller_modell", "notizen"]
autocomplete_fields = ["host", "verwaltet_von"]
inlines = [SchnittstelleInline, BridgeInline, GastInline]
fieldsets = [
(None, {"fields": ["art", "name", "slug", "status"]}),
("Hardware", {"fields": ["typ", "rolle", "hersteller_modell", "standort"]}),
("VM/LXC", {"fields": ["host", "proxmox_id", "betriebssystem"]}),
("Sonstiges", {"fields": ["verwaltet_von", "notizen"]}),
]
@admin.register(Bridge)
class BridgeAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["__str__", "host", "vlan_aware"]
list_filter = ["host", "vlan_aware"]
inlines = [IPAdresseInline]
@admin.register(Schnittstelle)
class SchnittstelleAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["__str__", "art", "mac", "bridge", "vlan_tag", "durchgereicht_an", "ssid"]
list_filter = ["art", "geraet__art", "bridge"]
search_fields = ["name", "mac", "geraet__name", "geraet__slug"]
autocomplete_fields = ["geraet", "durchgereicht_an"]
inlines = [IPAdresseInline]
fieldsets = [
(None, {"fields": ["geraet", "name", "art", "mac", "notizen"]}),
("Anbindung", {"fields": ["bridge", "vlan_tag", "durchgereicht_an", "ssid"]}),
("Switch-Port", {"fields": ["switch_modus", "untagged_vlan", "tagged_vlans", "poe"], "classes": ["collapse"]}),
]
@admin.register(Verbindung)
class VerbindungAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["__str__", "typ", "notiz"]
list_filter = ["typ"]
autocomplete_fields = ["a", "b"]
@admin.register(Netz)
class NetzAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["name", "slug", "cidr", "typ", "vlan_id", "gateway", "dhcp_von", "dhcp_bis", "standort"]
list_filter = ["typ", "standort"]
prepopulated_fields = {"slug": ["name"]}
inlines = [IPAdresseImNetzInline]
@admin.register(IPAdresse)
class IPAdresseAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["adresse", "netz", "zugeordnet_an", "art", "notiz"]
list_filter = ["netz", "art"]
search_fields = ["adresse", "notiz", "schnittstelle__name", "schnittstelle__geraet__name"]
autocomplete_fields = ["schnittstelle"]
@admin.register(SSID)
class SSIDAdmin(admin.ModelAdmin):
form = GeprueftesModelForm
list_display = ["name", "slug", "band", "netz", "ap"]
prepopulated_fields = {"slug": ["name"]}