Minimal input for autocomplete fields
This commit is contained in:
parent
e674f5b074
commit
74b8635413
3 changed files with 32 additions and 16 deletions
|
|
@ -223,6 +223,12 @@ class StudentAdmin(admin.ModelAdmin):
|
|||
return fieldsets
|
||||
return super().get_fieldsets(request, obj)
|
||||
|
||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||
ffield = super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
if db_field.name in self.autocomplete_fields:
|
||||
ffield.widget.attrs.update({'data-minimum-input-length': 3})
|
||||
return ffield
|
||||
|
||||
def archive(self, request, queryset):
|
||||
for student in queryset:
|
||||
# Save each item individually to allow for custom save() logic.
|
||||
|
|
@ -367,6 +373,12 @@ class AvailabilityInline(admin.StackedInline):
|
|||
}
|
||||
autocomplete_fields = ['corporation']
|
||||
|
||||
def formfield_for_foreignkey(self, db_field, request, **kwargs):
|
||||
ffield = super().formfield_for_foreignkey(db_field, request, **kwargs)
|
||||
if db_field.name in self.autocomplete_fields:
|
||||
ffield.widget.attrs.update({'data-minimum-input-length': 3})
|
||||
return ffield
|
||||
|
||||
|
||||
class PeriodAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'dates', 'section', 'level')
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue