form to override autocomplete organization changed

This commit is contained in:
asamihassan 2022-03-28 10:46:30 +05:00
parent e8f8ee8ad3
commit 9dc9daa1e0

View file

@ -9,20 +9,25 @@ from django.http import HttpResponse
import csv
from django import forms
from django.contrib.admin.widgets import AutocompleteSelect
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__
response = HttpResponse()