autoselect_on_singleton è ora connesso alle opzioni
parent
6ed94177dc
commit
e93193585f
|
|
@ -144,30 +144,6 @@ class RecapitoInline(StackedPolymorphicInline, DrillDownAutocompleteModelAdmin):
|
||||||
class IndirizzoInline(StackedPolymorphicInline.Child, DrillDownAutocompleteModelAdmin):
|
class IndirizzoInline(StackedPolymorphicInline.Child, DrillDownAutocompleteModelAdmin):
|
||||||
model = models.Indirizzo
|
model = models.Indirizzo
|
||||||
autocomplete_fields = ('dug','comune','cap','nazione',)
|
autocomplete_fields = ('dug','comune','cap','nazione',)
|
||||||
drilldown_autocomplete_fields = {
|
|
||||||
'cap': {
|
|
||||||
'linked': {
|
|
||||||
'comune': 'comuni',
|
|
||||||
},
|
|
||||||
'reset_on_included': {},
|
|
||||||
'reset_on_excluded': {},
|
|
||||||
'reset_on_reset': {},
|
|
||||||
'autoupdate_on_reset': False,
|
|
||||||
'autoselect_on_singleton': False,
|
|
||||||
'included_only': False,
|
|
||||||
},
|
|
||||||
'comune': {
|
|
||||||
'linked': {
|
|
||||||
'cap': 'cap',
|
|
||||||
},
|
|
||||||
'reset_on_included': {},
|
|
||||||
'reset_on_excluded': {},
|
|
||||||
'reset_on_reset': {},
|
|
||||||
'autoupdate_on_reset': False,
|
|
||||||
'autoselect_on_singleton': False,
|
|
||||||
'included_only': False,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class SedeInline(StackedPolymorphicInline.Child):
|
class SedeInline(StackedPolymorphicInline.Child):
|
||||||
model = models.Sede
|
model = models.Sede
|
||||||
|
|
@ -300,7 +276,7 @@ class IndirizzoAdmin(HiddenModel, DrillDownAutocompleteModelAdmin, RicercaOrdina
|
||||||
'reset_on_excluded': {},
|
'reset_on_excluded': {},
|
||||||
'reset_on_reset': {},
|
'reset_on_reset': {},
|
||||||
'autoupdate_on_reset': False,
|
'autoupdate_on_reset': False,
|
||||||
'autoselect_on_singleton': False,
|
'autoselect_on_singleton': True,
|
||||||
'included_only': False,
|
'included_only': False,
|
||||||
},
|
},
|
||||||
'comune': {
|
'comune': {
|
||||||
|
|
|
||||||
|
|
@ -65,6 +65,7 @@ class DrillDownAutocompleteJsonView(AutocompleteJsonView):
|
||||||
raise PermissionDenied from e
|
raise PermissionDenied from e
|
||||||
self.remote_model = remote_model
|
self.remote_model = remote_model
|
||||||
self.linkedfields = linkedfields
|
self.linkedfields = linkedfields
|
||||||
|
self.drilldown_field = drilldown_field
|
||||||
self.drilldown_filter_data = {
|
self.drilldown_filter_data = {
|
||||||
v: linkedfields[k] for k, v in drilldown_field['linked'].items() if k in linkedfields}
|
v: linkedfields[k] for k, v in drilldown_field['linked'].items() if k in linkedfields}
|
||||||
|
|
||||||
|
|
@ -75,11 +76,12 @@ class DrillDownAutocompleteJsonView(AutocompleteJsonView):
|
||||||
qs = super().get_queryset()
|
qs = super().get_queryset()
|
||||||
if getattr(self, 'drilldown_enabled', False):
|
if getattr(self, 'drilldown_enabled', False):
|
||||||
if hasattr(self, 'linkedfields'):
|
if hasattr(self, 'linkedfields'):
|
||||||
self.autoselect = False
|
if(self.drilldown_field['autoselect_on_singleton']):
|
||||||
|
self.autoselect = False
|
||||||
drilldown_filter_conditions = Q(**self.drilldown_filter_data)
|
drilldown_filter_conditions = Q(**self.drilldown_filter_data)
|
||||||
qs = qs.annotate(ddok=Max(Case(When(drilldown_filter_conditions, then=Value(
|
qs = qs.annotate(ddok=Max(Case(When(drilldown_filter_conditions, then=Value(
|
||||||
1)), default=Value(0)))).order_by('-ddok', *qs.query.order_by)
|
1)), default=Value(0)))).order_by('-ddok', *qs.query.order_by)
|
||||||
if qs.filter(ddok=1).count() == 1:
|
if not getattr(self,'autoselect',True) and qs.filter(ddok=1).count() == 1:
|
||||||
self.autoselect = True
|
self.autoselect = True
|
||||||
else:
|
else:
|
||||||
qs = qs.annotate(ddok=Value(1))
|
qs = qs.annotate(ddok=Value(1))
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue