@@ -32,15 +32,15 @@ def choices_from_queryset(queryset):
32
32
def choices_from_instance (instance , widget ):
33
33
"""
34
34
Builds choices from a model instance using the widgets queryset() method.
35
- If any of the widgets trigger fields is not defined on the instance or the
35
+ If any of the widgets trigger_field fields is not defined on the instance or the
36
36
instance itself is None, None is returned.
37
37
38
38
instance: An instance of the model used on the current admin page.
39
39
widget: A widget instance given to the FlexSelectWidget.
40
40
"""
41
41
try :
42
- for trigger in widget .triggers :
43
- getattr (instance , trigger )
42
+ for trigger_field in widget .trigger_fields :
43
+ getattr (instance , trigger_field )
44
44
except ObjectDoesNotExist :
45
45
return [('' , widget .empty_choices_text (instance ))]
46
46
@@ -49,16 +49,16 @@ def choices_from_instance(instance, widget):
49
49
def details_from_instance (instance , widget ):
50
50
"""
51
51
Builds html from a model instance using the widgets details() method. If
52
- any of the widgets trigger fields is not defined on the instance or the
52
+ any of the widgets trigger_field fields is not defined on the instance or the
53
53
instance itself is None, None is returned.
54
54
55
55
instance: An instance of the model used on the current admin page.
56
56
widget: A widget instance given to the FlexSelectWidget.
57
57
"""
58
58
try :
59
- for trigger in widget .triggers :
60
- getattr (instance , trigger )
61
- related_instance = getattr (instance , widget .db_field .name )
59
+ for trigger_field in widget .trigger_fields :
60
+ getattr (instance , trigger_field )
61
+ related_instance = getattr (instance , widget .base_field .name )
62
62
except ObjectDoesNotExist :
63
63
return u''
64
64
return widget .details (related_instance , instance )
@@ -70,15 +70,15 @@ def instance_from_request(request, widget):
70
70
"""
71
71
items = dict (request .POST .items ())
72
72
values = {}
73
- for f in widget .db_field .model ._meta .fields :
73
+ for f in widget .base_field .model ._meta .fields :
74
74
if f .name in items :
75
75
try :
76
76
value = f .formfield ().to_python (items [f .name ])
77
77
if value is not None :
78
78
values [f .name ] = value
79
79
except ValidationError :
80
80
pass
81
- return widget .db_field .model (** values )
81
+ return widget .base_field .model (** values )
82
82
83
83
class FlexSelectWidget (Select ):
84
84
"""
@@ -93,7 +93,7 @@ class FlexSelectWidget(Select):
93
93
# First a widget class for the field that should update when other
94
94
# fields change must be defined.
95
95
class CustomerContactRenderer(object):
96
- triggers = ['client']
96
+ trigger_fields = ['client']
97
97
empty_choices_text = 'Please update the client field first'
98
98
99
99
def details(self, instance):
@@ -105,16 +105,16 @@ def queryset(self, instance):
105
105
106
106
# Then the formfield_for_foreignkey() method of the ModelAdmin must be
107
107
# overwritten.
108
- def formfield_for_foreignkey(self, db_field , request, **kwargs):
109
- if db_field .name == "customer_contact":
108
+ def formfield_for_foreignkey(self, base_field , request, **kwargs):
109
+ if base_field .name == "customer_contact":
110
110
kwargs['widget'] = FlexSelectWidget(
111
111
# An instance of the widget class defined above.
112
112
widget=CustomerContactRenderer()
113
- db_field=db_field ,
113
+ base_field=base_field ,
114
114
modeladmin=self,
115
115
request=request,
116
116
)
117
- return super(CaseAdmin, self).formfield_for_foreignkey(db_field ,
117
+ return super(CaseAdmin, self).formfield_for_foreignkey(base_field ,
118
118
request, **kwargs)
119
119
"""
120
120
instances = {}
@@ -131,7 +131,7 @@ class Media:
131
131
def __init__ (self , db_field , modeladmin , request , * args ,
132
132
** kwargs ):
133
133
134
- self .db_field = db_field
134
+ self .base_field = db_field
135
135
self .modeladmin = modeladmin
136
136
self .request = request
137
137
@@ -146,7 +146,7 @@ def _hashed_name(self):
146
146
"""
147
147
salted_string = "" .join ([
148
148
settings .SECRET_KEY ,
149
- self .db_field .name ,
149
+ self .base_field .name ,
150
150
self .modeladmin .__class__ .__name__ ,
151
151
])
152
152
return hashlib .sha1 (salted_string ).hexdigest ()
@@ -167,21 +167,21 @@ def _get_instance(self):
167
167
168
168
def _build_js (self ):
169
169
"""
170
- Adds the widgets hashed_name as the key with an array of its triggers
170
+ Adds the widgets hashed_name as the key with an array of its trigger_fields
171
171
as the value to flexselect.selects.
172
172
"""
173
173
return """
174
174
<script>
175
175
var flexselect = flexselect || {};
176
- flexselect.triggers = flexselect.triggers || {};
177
- flexselect.triggers .%(field)s = flexselect.triggers .%(field)s ||
176
+ flexselect.trigger_fields = flexselect.trigger_fields || {};
177
+ flexselect.trigger_fields .%(field)s = flexselect.trigger_fields .%(field)s ||
178
178
[];
179
- flexselect.triggers .%(field)s.push(%(triggers )s);
179
+ flexselect.trigger_fields .%(field)s.push(%(trigger_fields )s);
180
180
</script>""" % {
181
- 'field' : self .db_field .name ,
182
- 'triggers ' :
181
+ 'field' : self .base_field .name ,
182
+ 'trigger_fields ' :
183
183
"," .join ('["%s", "%s"]' % (t , self .hashed_name )
184
- for t in self .triggers ),
184
+ for t in self .trigger_fields ),
185
185
};
186
186
187
187
0 commit comments