-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathadmin.py
67 lines (50 loc) · 2.01 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*- vim:fileencoding=utf-8:
# vim: tabstop=4:shiftwidth=4:softtabstop=4:expandtab
# Copyright (C) 2010-2014 GRNET S.A.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
from django.contrib import admin
from peers.models import PeerRange, TechcEmail, Peer, PeerNotify
from django import forms
from django.forms import ModelForm
from django.contrib.admin.widgets import FilteredSelectMultiple
class PeerAdminForm(ModelForm):
networks = forms.ModelMultipleChoiceField(
PeerRange.objects.all(),
widget=FilteredSelectMultiple("PeerRange", True),
required=False
)
techc_emails = forms.ModelMultipleChoiceField(
TechcEmail.objects.all(),
widget=FilteredSelectMultiple("TechcEmail", True),
required=False
)
class Meta:
model = Peer
fields = "__all__"
class PeerAdmin(admin.ModelAdmin):
search_fields = ['peer_name', 'networks__network']
form = PeerAdminForm
class PeerRangeAdmin(admin.ModelAdmin):
search_fields = ['network']
class TechcEmailAdmin(admin.ModelAdmin):
search_fields = ['email']
class PeerNotifyAdmin(admin.ModelAdmin):
list_display = ('peer', 'user', 'peer_activation_notified')
search_fields = ['peer__peer_name', 'user__username']
admin.site.register(Peer, PeerAdmin)
admin.site.register(PeerRange, PeerRangeAdmin)
admin.site.register(TechcEmail, TechcEmailAdmin)
admin.site.register(PeerNotify, PeerNotifyAdmin)