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

  • SEARCH
  • Home
  • 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 9213831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:50:25+00:00 2026-06-18T01:50:25+00:00

My form needs data from the request variable request.LANGUAGE_CODE but the forms.py file doesn’t

  • 0

My form needs data from the request variable request.LANGUAGE_CODE but the forms.py file doesn’t have any way of getting the request variable.

I use the “The set_language redirect view” to set the language and it works fine, but I need to randomly generate a select dropdown for a form, and I simply can’t get django to give me the language_code used.

The translation.get_language() used in the code snippet below only gives back ‘en-us’, but for every language.

class C21Form(ModelForm):
    principal_procedure_code= forms.ModelChoiceField(label=_('BlaBla'), queryset=diagCode.objects.filter(language=translation.get_language()))

Update:

forms.py

class C21Form(ModelForm):
    principal_procedure_code= forms.ModelChoiceField(label=_('BlaBla'), queryset=diagCode.objects.filter(language=language_code))

    def __init__(self, language_code=None, *args, **kwargs):
        self.language_code = language_code
        super(C21Form, self).__init__(*args, **kwargs)

views.py

 form = C21Form(request.LANGUAGE_CODE, request.POST)
  • 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-18T01:50:26+00:00Added an answer on June 18, 2026 at 1:50 am
    class C21Form(ModelForm):
        principal_procedure_code= forms.ModelChoiceField(label=_('BlaBla'), queryset=None)
    
        def __init__(self, language_code="hu", *args, **kwargs):
            super(C21Form, self).__init__(*args, **kwargs)
            self.fields['principal_procedure_code'].queryset = diagCode.objects.filter(language=language_code)
    

    Is a way it works, first I create an empty queryset, then filter it later.

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

Sidebar

Related Questions

I have a form data from an iphone app that needs to send HTTP
I have a form and I need to add some data from database before
I have to design a database to handle forms. Basically, a form needs to
My app pulls data from a website which uses Form based authentication. It needs
I have a web application written in CakePHP that needs to read request data
I need to submit data from a form to an SQL2005 database via a
I have created application where i just need to access data form assets folder.
I need to get some external data to form an output file name in
does curl function need any special option to post multipart/form-data ?
I have an html form. I need to send its data to flash on

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.