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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:20:23+00:00 2026-05-26T21:20:23+00:00

So, I have the following form: class DesignItemForm (forms.ModelForm): def __init__(self, *args, **kwargs): super(DesignItemForm,

  • 0

So, I have the following form:

class DesignItemForm (forms.ModelForm):
def __init__(self, *args, **kwargs):
    super(DesignItemForm, self).__init__(*args, **kwargs)
    CHOICES=[(i,i) for i in range(MAX_DESIGN_ITEM_QUANTITY)]
    self.fields['quantity'] = forms.ChoiceField(choices=CHOICES)    
class Meta:
    model = DesignItem
    fields = ('quantity','trackable',)

My view:

d = Design.object.get(slug=fromInput)
....
DesignItemInlineFormSet = inlineformset_factory(Design, DesignItem, fk_name="design", form=DesignItemForm,)

    if request.method == "POST":
    formset = DesignItemInlineFormSet(request.POST, request.FILES, instance=d)
    if formset.is_valid():
        formset.save() 
DesignItemInlineFormSet(instance=d)

As you can tell, in my form, I overwrote the quantity field to be a drop down instead of an integer field.

For some reason, when I submit the form, the data is not updated in the database. However, if I change the form to the following, it works (of course, it doesn’t have the dropdowns I want, but it posts to the db). Why is this, and how do I fix it?

class DesignItemForm (forms.ModelForm):
def __init__(self, *args, **kwargs):
    super(DesignItemForm, self).__init__(*args, **kwargs)
    # CHOICES=[(i,i) for i in range(MAX_DESIGN_ITEM_QUANTITY)]
    # self.fields['quantity'] = forms.ChoiceField(choices=CHOICES)  
class Meta:
    model = DesignItem
    fields = ('quantity','trackable',)

EDIT: Here is the DesignItem model:

class DesignItem(models.Model):
"""Specifies how many of an item are in a design."""
design = models.ForeignKey(Design, related_name="items")
quantity = models.PositiveIntegerField(default=1)
trackable = models.ForeignKey(Trackable, related_name="used")
  • 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-26T21:20:24+00:00Added an answer on May 26, 2026 at 9:20 pm

    have you tried just overriding the widget instead of the whole field?

    i guess you want a select widget

    def __init__(self, *args, **kwargs):
        super(DesignItemForm, self).__init__(*args, **kwargs)
        CHOICES=[(i,i) for i in range(MAX_DESIGN_ITEM_QUANTITY)]
        self.fields['quantity'].widget = forms.Select(choices=CHOICES)  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a following form: class PlayForwardPageForm(forms.ModelForm): def __init__(self, *args, **kwargs): super(PlayForwardPageForm, self).__init__(*args, **kwargs)
I have the following Form defined class MyForm(ModelForm): def __init__(self, readOnly=False, *args, **kwargs): super(MyForm,self).__init__(*args,**kwrds)
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 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 GuaranteesForm(forms.ModelForm): birth_date = forms.DateField(input_formats=['%d/%m/%Y'], required=True) However if the
I have the following form code: # forms.py class SomeForm(forms.Form): hello = forms.CharField(max_length=40) world
I have the following situation in my python code: class Parent(object): def run(self): print
I'm looking at some Java classes that have the following form: public abstract class
I have the following form for photo_album which uses the nested forms feature of

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.