form to override autocomplete organization changed
This commit is contained in:
parent
e8f8ee8ad3
commit
9dc9daa1e0
1 changed files with 14 additions and 9 deletions
23
app/admin.py
23
app/admin.py
|
@ -9,19 +9,24 @@ from django.http import HttpResponse
|
|||
import csv
|
||||
from django import forms
|
||||
from django.contrib.admin.widgets import AutocompleteSelect
|
||||
|
||||
class autocomplete_fields_form(forms.ModelForm):
|
||||
class autocomplete_fields_form(forms.ModelForm):
|
||||
"""This form overrides autocomplete
|
||||
organization field for Person class
|
||||
"""
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(autocomplete_fields_form, self).__init__(*args, **kwargs)
|
||||
|
||||
# self.fields['organization'].label = 'My new label'
|
||||
|
||||
|
||||
class Meta:
|
||||
widgets = {
|
||||
'my_field': AutocompleteSelect(
|
||||
Person._meta.get_field('organization').remote_field,
|
||||
admin.site,
|
||||
attrs={'data-dropdown-auto-width': 'true'}
|
||||
),
|
||||
}
|
||||
model = Person
|
||||
fields = '__all__'
|
||||
widgets={
|
||||
'organization': forms.Select(attrs={'style': 'width:750px'})
|
||||
}
|
||||
|
||||
|
||||
|
||||
def download_csv(modeladmin, request, queryset):
|
||||
name = queryset[0].__class__.__name__
|
||||
|
|
Loading…
Reference in a new issue