ajouter vhc_info/add url param for nType
This commit is contained in:
@@ -38,8 +38,16 @@ class _vhc_infos_admin_form(forms.ModelForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(_vhc_infos_admin_form, self).__init__(*args, **kwargs)
|
||||
if 'initial' in kwargs and 'Vehicle' in kwargs['initial']:
|
||||
self.fields['Vehicle'].queryset = Vehicles.objects.filter(id=kwargs['initial']['Vehicle'])
|
||||
if 'initial' in kwargs:
|
||||
initial = kwargs.get('initial', {})
|
||||
if 'Vehicle' in kwargs['initial']:
|
||||
vehicle_id = initial.get('Vehicle')
|
||||
if vehicle_id:
|
||||
self.fields['Vehicle'].initial = vehicle_id
|
||||
if 'nType' in kwargs['initial']:
|
||||
nType_value = initial.get('nType')
|
||||
if nType_value:
|
||||
self.fields['nType'].initial = nType_value
|
||||
class _vhc_infos_admin(admin.ModelAdmin):
|
||||
form = _vhc_infos_admin_form
|
||||
always_show_username = True
|
||||
@@ -88,6 +96,22 @@ class _vhc_infos_admin(admin.ModelAdmin):
|
||||
if not self.always_show_username:
|
||||
return name or username
|
||||
return (name and name != username and '%s (%s)' % (name, username) or username)
|
||||
def get_changeform_initial_data(self, request):
|
||||
"""
|
||||
Return initial data for the admin form.
|
||||
"""
|
||||
initial = super(_vhc_infos_admin, self).get_changeform_initial_data(request)
|
||||
get_data = request.GET.copy()
|
||||
|
||||
# Pré-remplir le champ 'Vehicle'
|
||||
if 'Vehicle' in get_data:
|
||||
initial['Vehicle'] = get_data.get('Vehicle')
|
||||
|
||||
# Pré-remplir le champ 'nType'
|
||||
if 'nType' in get_data:
|
||||
initial['nType'] = get_data.get('nType')
|
||||
|
||||
return initial
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user