source: django_apps/wndb/admin.py@ 369

Last change on this file since 369 was 340, checked in by Rick van der Zwet, 13 years ago

Initial idea of Wireless Nodes DataBase.

File size: 987 bytes
RevLine 
[340]1from wndb.models import *
2from django.contrib import admin
3from django.db.models import get_models, get_app
4from django.contrib.admin.sites import AlreadyRegistered
5from django import forms
6from django.db.models import Q
7
8class InterfaceInline(admin.TabularInline):
9 extra = 3
10 model = Interface
11
12class NodeAdmin(admin.ModelAdmin):
13 inlines = [
14 InterfaceInline,
15 ]
16
17admin.site.register(Node,NodeAdmin)
18
19class LinkForm(forms.ModelForm):
20 def __init__(self, *args, **kwargs):
21 super(LinkForm, self).__init__(*args, **kwargs)
22 if 'initial' in kwargs:
23 self.fields['ip_block'].queryset = IPBlock.objects.filter(Q(link__isnull=True))
24 else:
25 self.fields['ip_block'].queryset = IPBlock.objects.filter(Q(link__isnull=True)|Q(pk=self.instance.ip_block.id))
26
27class LinkAdmin(admin.ModelAdmin):
28 form = LinkForm
29
30admin.site.register(Link,LinkAdmin)
31
32
33for model in get_models(get_app('wndb')):
34 try:
35 admin.site.register(model)
36 except AlreadyRegistered:
37 pass
Note: See TracBrowser for help on using the repository browser.