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 6361239
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:45:04+00:00 2026-05-24T23:45:04+00:00

I have form class: class Form(forms.ModelForm): id = forms.ModelChoiceField(queryset=Option.objects.all(), widget=forms.HiddenInput()) category = forms.ModelChoiceField(queryset=Category.objects.all()) class

  • 0

I have form class:

class Form(forms.ModelForm):
    id = forms.ModelChoiceField(queryset=Option.objects.all(), widget=forms.HiddenInput())
    category = forms.ModelChoiceField(queryset=Category.objects.all())

    class Meta:
        model = Option
        fields = ('id', 'category')

    def choices(self, ext_data):
        # something with extdata...
        choices = [('1','one')]
        category = forms.ModelChoiceField(queryset=choices)

but this:

my_form.choices(something)

is not working. Why?

I must implement this in class because i have one view and many different forms. Each form have specific choices function.

  • 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-05-24T23:45:04+00:00Added an answer on May 24, 2026 at 11:45 pm

    First, queryset must be a queryset, not a list, since you’re using ModelChoiceField. Second, to reference the category form field use self.fields['category']. Your function should thus look something like this:

    def choices(self, ext_data):  
        #I'm not sure what ext_data is, but I suspect it's something to filter the Categories
        self.fields['category'].queryset = Category.objects.filter(something=ext_data)
    
        #If ext_data itself is a queryset you can use it directly:
        self.fields['category'].queryset = ext_data
    

    For clarification, a queryset is what you get when you use Model.objects.filter(xxx) or any other filtering action on your model.

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

Sidebar

Related Questions

I have form: class Form(forms.ModelForm): id = forms.ModelChoiceField(queryset=Category.objects.all(), widget=forms.HiddenInput()) def choices(self): items = ...query
I have form: class ItemForm(forms.ModelForm): id = forms.ModelChoiceField(queryset=Item.objects.all(), widget=forms.HiddenInput()) temp = forms.BooleanField(widget=forms.HiddenInput(), required=False) date
I have form: class AdmItemForm(forms.ModelForm): id = forms.ModelChoiceField(queryset=Article.objects.all(), widget=forms.HiddenInput()) mainimage = forms.ImageField(widget=AdmImageWidget(), required=False) tags
I have the following form: class FeaturedVideoForm(ModelForm): featured_video = forms.ModelChoiceField(Video.objects.none() widget=make_select_default, required=False, empty_label='No Featured
I have the following form: class ModuleItemForm2(forms.ModelForm): class Meta: model = Module_item fields =
I have the following model and it's form: class Project(models.Model) class ProjectForm(forms.ModelForm) class Meta:
I Have this Form class MyModelForm(forms.ModelForm): boolfield = forms.TypedChoiceField(coerce=bool, choices=((False, 'No'), (True, 'Yes')), widget=forms.RadioSelect
I have a following form: class PlayForwardPageForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PlayForwardPageForm, self).__init__(*args, **kwargs)
I have a form looking like this: class MarketingActionForm(forms.ModelForm): contact = ManyToManyByLetter(Contact, field_name=first_name) #contact
I have in my models.py class Business(models.Model): industry = models.models.ManyToManyField(Industry) in forms.py class BusinessForm(forms.ModelForm):

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.