Is it possible to save an object through Django HTML form with the value in option tag directly?
<select class="form-control" name="person">
<option selected disabled>Choose</option>
{% for person in group %}
<option value="{{ person }}">{{ person.name }}</option>
{% endfor %}
</select>
class Group(models.Model):
group_name = models.CharField(max_length=255, blank=True)
person = models.ForeignKey(Person, on_delete=models.CASCADE)
def __str__(self):
return self.group_name
Tried the above but I get "didn't return a HttpResponse object". I know I can pass an ID but is it possible to save the object directly instead of going to views.py and getting the object via an ID?