Last change
on this file since 398 was 340, checked in by Rick van der Zwet, 13 years ago |
Initial idea of Wireless Nodes DataBase.
|
File size:
987 bytes
|
Rev | Line | |
---|
[340] | 1 | from wndb.models import *
|
---|
| 2 | from django.contrib import admin
|
---|
| 3 | from django.db.models import get_models, get_app
|
---|
| 4 | from django.contrib.admin.sites import AlreadyRegistered
|
---|
| 5 | from django import forms
|
---|
| 6 | from django.db.models import Q
|
---|
| 7 |
|
---|
| 8 | class InterfaceInline(admin.TabularInline):
|
---|
| 9 | extra = 3
|
---|
| 10 | model = Interface
|
---|
| 11 |
|
---|
| 12 | class NodeAdmin(admin.ModelAdmin):
|
---|
| 13 | inlines = [
|
---|
| 14 | InterfaceInline,
|
---|
| 15 | ]
|
---|
| 16 |
|
---|
| 17 | admin.site.register(Node,NodeAdmin)
|
---|
| 18 |
|
---|
| 19 | class 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 |
|
---|
| 27 | class LinkAdmin(admin.ModelAdmin):
|
---|
| 28 | form = LinkForm
|
---|
| 29 |
|
---|
| 30 | admin.site.register(Link,LinkAdmin)
|
---|
| 31 |
|
---|
| 32 |
|
---|
| 33 | for 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.