Am trying to save dropdown in django without using django forms am directly getting the form values to views.
This is my view:
class WelcomeForm(ModelForm):
message = forms.CharField(widget=forms.Textarea)
class Meta:
model = Welcome
fields = [ 'message', 'courses']
try:
courses = Course.objects.all()
except ObjectDoesNotExist:
courses = None
form = WelcomeForm()
if request.method == 'POST':
form = WelcomeForm(request.POST)
if form.is_valid():
_process = form.save(commit=False)
_process.save()
messages.success(request, 'Welcome settings has been added successfully')
context = {'courses': courses}
return render(request, 'welcome/add_form.html', context)
And thus, using courses in my dropdown:
<select class="form-select" data-search="on"name="courses" multiple>
<option></option>
{% for data in courses %}
<option value="{{data.name}}">{{data.name}}</option>
{% endfor %}
</select>
From the above, i can save name of the course, but i also need slug of the course to make user clickable ! HOw to save two values from the selected options ?