Wednesday, May 31, 2017

value of checkbox aren't saved in the form

i am a beginner with Django. I don''t know what the problem with the value of checkbox. When i enter to the saved form the value of checkbox aren't save.The image is here . Please I need your help, I loose too much time on this.

This is my

class BacktestForm(forms.ModelForm):

period_start = forms.DateField( - datetime.timedelta(days=365+16), widget=forms.widgets.DateInput(format="%Y/%m/%d"), input_formats=["%Y/%m/%d"])
period_end = forms.DateField( - datetime.timedelta(days=16), widget=forms.widgets.DateInput(format="%Y/%m/%d"), input_formats=["%Y/%m/%d"])
        market = forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple, choices=MARKET_CHOICES)
        sector = forms.MultipleChoiceField(required=False,widget=CheckboxSelectMultiple, choices= MEDIA_CHOICES)
class Meta:
model = Parameters

This is my

class Parameters(models.Model):

user = models.ForeignKey(User)
title = models.CharField('title', max_length=100, default='', blank=True, help_text='Use an indicative name, related to the chosen parameters')
type = models.CharField('forecast type', choices=FORECAST_TYPES, max_length=20, default="backtest")

#input characteristics
price_1_min = models.FloatField('1. Price, min', default=0.1, validators=[MinValueValidator(0.1), MaxValueValidator(20000)])

def get_backtest_url(self):
return reverse('saved_backtest', kwargs={'pk':})

The save function in

        if request.method == 'POST':
if form.is_valid():
if 'save' in request.POST:
obj = False)
obj.user = request.user
obj.type = "backtest", 'Saved!')
return redirect(obj.get_backtest_url())

The template for the saved form is :

 <div> {% if user.is_authenticated %}
{% if user.profile.is_active %}
                                     &nbsp; Saved from "Backtesting"
{% for param in user.parameters_set.all %}
{% if param.type == "backtest" %}
                                                         <table style="width:100%">
                                                           <th> Saved File </th>
                                                           <th> Created at </th>
                                                           <td> <a href='{{param.get_backtest_url}}'>{{param.title}}  </a> </td>
  <td> {{param.created_at}} </td>
{% endif %}
{% endfor %}

You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment