from django import forms from .models import Devices # class DevicesForm(forms.ModelForm): # class Meta: # model = Devices # fields = ['identifier_name','device_name','operating_system','department','used_by','zone', # 'continents','region','cluster','pod', "device_unique_id" ] class DevicesForm(forms.ModelForm): class Meta: model = Devices fields = ['identifier_name', 'device_name', 'operating_system', 'department', 'used_by', 'zone', 'continents', 'region', 'cluster', 'pod', "device_unique_id"] def __init__(self, *args, **kwargs): super(DevicesForm, self).__init__(*args, **kwargs) # If you want to prepopulate used_by, you could set it here or handle in the view if 'used_by' in kwargs: self.fields['used_by'].initial = kwargs['used_by'] class EditDevicesForm(forms.ModelForm): class Meta: model = Devices fields = ['identifier_name','device_name','operating_system','department','used_by','zone', 'continents','region','cluster','pod']