save the variation of radio buttons django


Hello i have a form with three radio buttons they aren't a part of But when the user click on radio buttons i want to save their value in a variable called strategy in I defined in views : request.Post.get ('tabs') the name of radio buttons. But the error was **('WSGIRequest' object has no attribute 'Post')** Everything is saved excluding the value of radio buttons.

    class Parameters(models.Model):
    MARKET= ((1,'Nasdaq'),(2, 'Nyse'),(3,'Amex'),)  
    SECTOR_CHOICES = ((1,'Utilities'),(2, 'Basic Materials'),(3,'Healthcare'), (4,'Services'),(5,'Financial'),)

    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")
    strategy = models.CharField('Strategy', choices=STRATEGY_CHOICES, max_length=20,default="Long")

    #input characteristics
    price_1_min                = models.FloatField('1. Price, min', default=0.1, validators=[MinValueValidator(0.1), MaxValueValidator(20000)])
    price_1_max                = models.FloatField('1. Price, max', default=20000, validators=[MinValueValidator(0.1), MaxValueValidator(20000)])
    stocks_num_2_min            = models.IntegerField('2. Number of selected stock, min', default=3, validators=[MinValueValidator(0), MaxValueValidator(100)])
    stocks_num_2_max            = models.IntegerField('2. Number of selected stock, max', default=7, validators=[MinValueValidator(1),])
    holding_period                          = models.IntegerField('3. Holding Period', default=1, validators=[MinValueValidator(1),])
    volume                                  = models.IntegerField('4. Volume', default=0, validators=[MinValueValidator(0),])
    market = models.CharField('Market', max_length=30, null=True)
    sector= models.CharField('Sector', max_length=30, null=True)

    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(label='Market', choices=Parameters.MARKET, widget=forms.CheckboxSelectMultiple)
        sector = forms.MultipleChoiceField(label='Sector', choices=Parameters.SECTOR_CHOICES, widget=forms.CheckboxSelectMultiple)
    class Meta:
        model = Parameters
        exclude = [
            'title': forms.TextInput(attrs={'placeholder':'for ex. highLimitLowPrice'}),
                        'sector': forms.CheckboxSelectMultiple(),


     <div class="row">
        <div class='col-md-9'> 
                  <div id="tabs">

                   <input type="radio" name="tabs" id="toggle-tab1"  checked="checked" />
                   <label for="toggle-tab1">Long</label>

                   <input type="radio" name="tabs" id="toggle-tab2"    />
                   <label for="toggle-tab2">Short</label>

                   <input type="radio" name="tabs" id="toggle-tab3"   />
                   <label for="toggle-tab3">Long and Short</label>
                   <div id="tab1" class="tab"  >
            <form action="{% url "backtest" %}" method='POST' role='form' id='form'>
                {% csrf_token %}
                {% include 'tags/parameters_form.html' %}
                <br />
                {% include 'tags/parameters_backtest_form.html' %}
                                {% if user.is_authenticated %}
                                <input type='submit' id='run' value='Run' class='btn btn-default'>
                    {% if user.profile.is_active %}
                        Name: {{ form.title }} <input type='submit' name='save' value='Save' class='btn btn-default'>
                    {% else %}
                        Expired account! you need to reactivate in order to save parameters.
                    {% endif %}
                {% else %}
                                         Please <a href="{% url 'auth_login' %}">login</a> in order to Run backtesting!
                     Our system needs your email in order to notify you once one or more of your simulations are done. This is a safer way for you to keep track of your previous simulations (/jobs).   
                                  {% endif %}                        

                        </form> (for the save function):

    def backtest(request, pk=None):

    if pk is not None:
        param = get_object_or_404(Parameters, pk=pk, user=request.user)
        form = BacktestForm(request.POST or None, instance=param)
        form = BacktestForm(request.POST or None)
        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())

 June 7, 2017, 3:50 a.m. 0 Answer

Warning! You are not logged in.
Your answer will be published as Guest user.

Post your Answer

 Prev question