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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:07:37+00:00 2026-06-02T16:07:37+00:00

I’m not sure how to tackle this problem – I’ve tried a bunch of

  • 0

I’m not sure how to tackle this problem – I’ve tried a bunch of things but the outcome is that I get a “too many values to unpack” error after submitting the form.

This is a simple demo of the models that are in play:

class Supplier(models.Model):
    name = models.CharField(max_length=100)

class SupplierLocation(models.Model):
    supplier = models.ForeignKey(Supplier)
    location = models.CharField(max_length=100)

class Product(models.Model):
    supplier = models.ForeignKey(Supplier)
    name = models.CharField(max_length=100)
    price = models.DecimalField(decimal_places=2,max_digits=10)

What I’m trying to do is produce a form that has 2 lots of radio buttons. SupplierLocation.location is the labels and SupplierLocation.id would be the value for the radio button. Likewise Product.name would be the label and Product.id would be the value for the radio button. The idea is that I want to group them into blocks sorted by Supplier.id so that the html looks something like this:

<div>
    <table>
        <tr class="{{ Supplier.name }} hidden">
            <td>{{ location.name }}</td>
            <td><input type="radio" name="location_id" value="{{ location.id }}" /></td>
        </tr>
    </table>
    <table>
        <tr class="{{ Supplier.name }} hidden">
            <td>{{ product.name }}</td>
            <td>{{ product.price }}</td>
            <td><input type="radio" name="product_id" value="{{ product.id }}" /></td>
        </tr>
    </table>
</div>

Obviously there would be multiple rows in both tables and I’m pretty sure that I should be able to use a widget in place of the hardcoded input fields however I’m puzzled how to achieve the custom form. The idea is that all the fields are hidden when the page loads and when a supplier is chosen from a link on the page the fields are made visible with JS.

I’m unsure what the form should look like and whether I should be using a modelform or a standard form. In my current test I have a form that looks like this:

forms.py

class ProductLocationForm(forms.Form):
    PRODUCT_CHOICES = [(p.id, p.name) for p in Product.objects.all()]
    LOCATION_CHOICES = [(l.id, l.name) for l in SupplierLocation.objects.all()]
    product = forms.ChoiceField(widget=forms.RadioSelect, choices=PRODUCT_CHOICES)
    location = forms.ChoiceField(widget=forms.RadioSelect, choices=LOCATION_CHOICES)

This gives me the products and locations but is missing the groupings by supplier or any way of isolating the supplier so I can hide/show them with JS.

Any help would be awesome.

  • 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-02T16:07:38+00:00Added an answer on June 2, 2026 at 4:07 pm

    You can use ModelChoiceField instead of constructing choices manually. Then you’ll have a queryset attribute for the field and will be able to something like that in the templates:

    {% regroup form.fields.product.queryset by supplier as grouped_products %}
    {% for gp in grouped_products %}
        Supplier: {{ gp.grouper }} 
        {% for choice in gp.list %}
            <input type="radio" name="product" value="{{ choice.pk }}" /> {{ choice }}
        {% endfor %}
    {% endfor %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I need a function that will clean a strings' special characters. I do NOT
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
this is what i have right now Drawing an RSS feed into the php,

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.