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 import csv
from django import forms from django import forms
from django.contrib.admin.widgets import AutocompleteSelect from django.contrib.admin.widgets import AutocompleteSelect
class autocomplete_fields_form(forms.ModelForm): class autocomplete_fields_form(forms.ModelForm):
"""This form overrides autocomplete """This form overrides autocomplete
organization field for Person class 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: class Meta:
widgets = { model = Person
'my_field': AutocompleteSelect( fields = '__all__'
Person._meta.get_field('organization').remote_field, widgets={
admin.site, 'organization': forms.Select(attrs={'style': 'width:750px'})
attrs={'data-dropdown-auto-width': 'true'}
),
} }
def download_csv(modeladmin, request, queryset): def download_csv(modeladmin, request, queryset):
name = queryset[0].__class__.__name__ name = queryset[0].__class__.__name__
response = HttpResponse() response = HttpResponse()