Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:34:18+00:00 2026-06-14T14:34:18+00:00

this is my forms.py CHOICES = [] class salDeptChartForm(forms.Form): company = forms.CharField(max_length=2,label = ‘Firma’,help_text=’A

  • 0

this is my forms.py

CHOICES = []
class salDeptChartForm(forms.Form):
    company = forms.CharField(max_length=2,label = 'Firma',help_text='A valid email address, please.')
    date_validfrom = forms.DateField(label = 'Bu Tarihten',required=False)
    date_validuntil = forms.DateField(label = 'Bu Tarihe Kadar',required=False)
    saldept = forms.MultipleChoiceField(label = 'Satış Departmanları',choices=CHOICES,    widget=forms.CheckboxSelectMultiple())

this is where I override the choices in my view.

    form = salDeptChartForm(initial={'company':'01'})
    saldeptlist = saleinstance.fetchSalDept()
    form.fields['saldept'].choices = saldeptlist <this is where I override>

problem occurs when I select one of the options. form doesnt get validate.

Select a valid choice. * is not one of the available choices.

I think, even I override the choices in my view django still checks with previous choices itially I created. I get the correct html output tough.

How to overcome this?
thx

complete view code is there.
form initiates twice one for get and one for post, I dont know if its best either.

def salDept(request):
    member_id = request.session['member_id']
    saleinstance = sale(member_id)
    chartinstance = charts(member_id)
    if request.method == 'GET':
        form = salDeptChartForm(initial={'company':'01'})  <first init>
        saldeptlist = saleinstance.fetchSalDept()  <its a list>
        form.fields['saldept'].choices = saldeptlist  <override choices>
        print 'get worked'
        return render(request, 'chart/sale/salDept.html',locals())
    if request.method == 'POST':
        form = salDeptChartForm(request.POST) <second init>
        print 'post worked'
        if form.is_valid(): <fails>
            print 'valid'
            company = form.cleaned_data['company']
            vfr = form.cleaned_data['date_validfrom']
            vun = form.cleaned_data['date_validuntil']
            validfrom = formatDate(vfr)
            validuntil = formatDate(vun)
            selectedSalDepts = request.POST.getlist('saldept')
        else:
            print 'not valid'
            print form.errors
        resultdict = chartinstance.salesBySaldept(company,selectedSalDepts,validfrom, validuntil)
        form = salDeptChartForm(initial={'company':company,'date_validfrom':request.POST['date_validfrom'], 'date_validuntil':request.POST['date_validuntil']})
        domcache = 'true'
        return render(request, 'chart/sale/salDept.html',locals())
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:34:20+00:00Added an answer on June 14, 2026 at 2:34 pm

    Your validation fails because you only overwrite the choices on the GET method. You don’t do anything for the POST, so as far as Django knows, no choice is valid for the POST. Adding the choices to POST should fix your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form that looks like this: class SampleForm(forms.Form): text = forms.CharField(max_length=100) In
this is my form: class IPTrackerSearchForm(forms.Form): keyword = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'size':'50'})) search_in = forms.ChoiceField(required=False, choices=ANY_CHOICE
views.py if pform.is_valid(): user = pform.save() forms.py class UserProfileForm(forms.ModelForm): sex = forms.CharField(max_length = 20,label=I
I have a number of forms like this: <form class=some-name> <input type=hidden name=bill valueflower
I have something like this: forms.py: AVATAR_CHOICES = (('1','option1'), ('2','option2'), ('3','option3'), ('4','option4')) class RegistrationForm(forms.Form):
forms.py class UserProfileForm(forms.ModelForm): phone = forms.CharField(max_length = 15,widget = forms.TextInput(attrs = {'placeholder':'Enter mobile no.
userform class UserForm(forms.ModelForm): confirm_password = forms.CharField(label=Confirm Password,widget=forms.PasswordInput(attrs = {'placeholder': 'Confirm Password','class':'required'})) phone = forms.CharField(max_length
class Test(forms.Form): def set_choices(self, choices): self.choices = choices def get_choices(self): return self.choices options =
I have a form: class MatchForm(forms.Form): base_field = forms.CharField(widget=forms.Select) def __init__(self ,*args, **kwargs): BASE_FIELDS
I have form: class Form(forms.ModelForm): id = forms.ModelChoiceField(queryset=Category.objects.all(), widget=forms.HiddenInput()) def choices(self): items = ...query

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.