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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:47:24+00:00 2026-05-12T00:47:24+00:00

Alright, I’m having a hard time explaining this, let me know if I should

  • 0

Alright, I’m having a hard time explaining this, let me know if I should fill you in on more details.

My url looks like this: http://domain.com/<category>/
Each <category> may have one or many sub categories.

I want the category page to have a form with a select box (among other fields) containing the category sub-categories.
I’ve currently hard coded the form in one of the templates, but I want to make it reflect the model directly.

In my currently hard coded solution, I have in my category view:

s = Category.objects.filter(parents__exact=c.id)  

that the form template iterates through and prints out the select box (see model code below)

I’m guessing I want a ModelFormSet with an init that filters out the categories, but I can’t seem to find how to do it in the docs.

Been looking at How do I filter ForeignKey choices in a Django ModelForm? as well, but I can’t get it to work properly.

My models

# The model that the Form should implement
class Incoming(models.Model):
    cat_id = models.ForeignKey(Category)
    zipcode = models.PositiveIntegerField()
    name = models.CharField(max_length=200)
    email = models.EmailField()
    telephone = models.CharField(max_length=18)
    submit_date = models.DateTimeField(auto_now_add=True)
    approved = models.BooleanField(default=False)

# The categories, each category can have none or many parent categories
class Category(models.Model):
    name = models.CharField(max_length=200, db_index=True)
    slug = models.SlugField()
    parents = models.ManyToManyField('self',symmetrical=False, blank=True, null=True)

    def __unicode__(self):
        return self.name

My form

class IncomingForm(ModelForm):
    class Meta:
        model = Incoming
  • 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-12T00:47:24+00:00Added an answer on May 12, 2026 at 12:47 am

    I would edit Daniel Rosemans reply and vote it winner, but since i cant edit it i will post the correct answer here:

    class IncomingForm(ModelForm):
        class Meta:
            model = Incoming
    
        def __init__(self, *args, **kwargs):
            super(IncomingForm, self).__init__(*args, **kwargs)
            if self.instance:
                self.fields['cat_id'].queryset = Category.objects.filter(
                        parents__exact=self.instance.id)
    

    The difference is self.fields[‘cat_id’] (correct) vs self.fields[‘parents’] (wrong, we both made the same mistake)

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

Sidebar

Ask A Question

Stats

  • Questions 183k
  • Answers 183k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Roll your own. I'm sure Tweetie 2's is custom; and… May 12, 2026 at 4:36 pm
  • Editorial Team
    Editorial Team added an answer Right-click on the solution in Solution Explorer, click Properties (If… May 12, 2026 at 4:36 pm
  • Editorial Team
    Editorial Team added an answer problem #1: body { width: 20%; } That's being applied… May 12, 2026 at 4:36 pm

Related Questions

Alright, I have been doing the following (variable names have been changed): FileInputStream fis
Alright, I'm trying to read a comma delimited file and then put that into
Alright, I know how the fieldset / legend works out in HTML. Say you
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, I am going to state up front that this question may be too

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.