Reputation: 2122
I am using crispy forms to build my form. Now i want to add one more extra <option>
tag with value in my timesheet_jobs
field which is Foreign Key Field. Please help me to add one more extra <option>
field in my <select>
at the end after loading all the options.
forms.py
class ClockInForm(forms.ModelForm):
class Meta:
model = TimesheetEntry
fields = ['timesheet_jobs', 'timesheet_clock_in_date', 'timesheet_clock_in_time']
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Upvotes: 1
Views: 553
Reputation: 1412
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
timesheet_jobs = self.fields['timesheet_jobs']
timesheet_jobs.choices = list(timesheet_jobs.choices)
timesheet_jobs.choices.append(tuple(('create_new_job', 'Create New Job')))
Upvotes: 1