Django get selected value

Django get selected value

Postby VolodymyrKirichinets » Sat Jul 23, 2016 3:01 pm

Hi, i have a problem with selected value
my models.py:
Code: Select all
class Model2(models.Model):
    ..................................................................................................................................
    choice_field = models.ManyToManyField(to=Model1, max_length=77, blank=True)
    ...................................................................................................................................

class Model2Form(ModelForm):
    class Meta:
        model = Forecast
        fields = ['choice_field', ...................................]

my views.py:
Code: Select all
def myfunc(request):
    form = Model2Form()
    if request.method == 'POST':
        form1 = Model2Form(request.POST)
        if form1.is_valid():
            form1.save()
        return ...............................................
    query1 = Model2.objects.values('choice_field').last()

In template.html when I try {{ query1.choice_field }} - i get {'choice_field': 5}. How can I get a name of currently selected choice_field item and/or value of currently selected choice_field item?
Last edited by Yoriz on Sat Jul 23, 2016 4:40 pm, edited 1 time in total.
Reason: First post lock.
VolodymyrKirichinets
 
Posts: 1
Joined: Sat Jul 23, 2016 2:43 pm

Return to Web Development

Who is online

Users browsing this forum: No registered users and 1 guest