-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfields.py
67 lines (50 loc) · 2.09 KB
/
fields.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
from django import forms
from django.contrib import admin
from clusters.models import *
from clusters.widgets import *
#class ChoicesWrapper(admin.widgets.RelatedFieldWidgetWrapper):
class FunctionResourceChoiceFieldX(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
super(FunctionResourceChoiceField, self).__init__(*args, **kwargs)
self.widget = admin.widgets.RelatedFieldWidgetWrapper(
#forms.widgets.Select(),
ResourceSelectWidget(),
FunctionResourceType._meta.get_field('resource_type').rel,
admin.site,
)
class FunctionResourceChoiceField(forms.MultiValueField):
widget = ResourceSelectWidget
def __init__(self, *args, **kwargs):
fields = (
forms.ChoiceField(),
forms.ChoiceField(),
)
super(FunctionResourceChoiceField, self).__init__(fields, *args, **kwargs)
def compress(self, data_list):
if data_list:
return data_list
return None
class FunctionAgentChoiceField(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
super(FunctionAgentChoiceField, self).__init__(*args, **kwargs)
self.widget = admin.widgets.RelatedFieldWidgetWrapper(
forms.widgets.Select(),
AgentFunction._meta.get_field('agent').rel,
admin.site,
)
class AgentResourceChoiceField(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
super(AgentResourceChoiceField, self).__init__(*args, **kwargs)
self.widget = admin.widgets.RelatedFieldWidgetWrapper(
forms.widgets.Select(),
AgentResourceType._meta.get_field('resource_type').rel,
admin.site,
)
class AgentFunctionChoiceField(forms.ModelChoiceField):
def __init__(self, *args, **kwargs):
super(AgentFunctionChoiceField, self).__init__(*args, **kwargs)
self.widget = admin.widgets.RelatedFieldWidgetWrapper(
forms.widgets.Select(),
AgentFunction._meta.get_field('function').rel,
admin.site,
)