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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:58:59+00:00 2026-05-23T09:58:59+00:00

I am working on the following: # models.py class FinancialProduct(models.Model): active = models.BooleanField(default=True) businesses

  • 0

I am working on the following:

# models.py

class FinancialProduct(models.Model):
    active = models.BooleanField(default=True)
    businesses = models.ManyToManyField(Business)
    name = models.CharField(max_length=40, unique=True)

class Item(models.Model):
    main_client = models.ForeignKey(Client)
    financial_product = models.ForeignKey(FinancialProduct)
    advisor = models.ForeignKey(User, blank=True, null=True)
    business = models.ForeignKey(Business)

class Business(models.Model):
    active = models.BooleanField(default=True)
    name = models.CharField(max_length=40, unique=True)

# forms.py

class ItemForm(ModelForm):

    def __init__(self,fpID,*args,**kwargs):
        super(ItemForm, self).__init__(*args, **kwargs)
        self.fields['advisor'].queryset = User.objects.filter(groups__name='advisor')
        self.fields['business'].queryset = Business.objects.filter(financialproduct__businesses=fpID)

    class Meta:
        model = Item
        exclude = ('main_client', 'financial_product')

    def CustomSave(self,f,c,u):
        idb = self.save(commit=False)
        idb.financial_product = f
        idb.main_client = c
        return idb.save()

And I created the following data:

Business(1,'Company1')
Business(1,'Company2')
FinancialProduct(1,'Company1', 'Small Product')
FinancialProduct(1,'Company1,Company2', 'Large Product')

In the front end I get the following:

Select 'Small Product' > Get ('Company 1', 'Company 1', 'Company 2')
Select 'Large Product' > Get ('Company 1', 'Company 2')

Unfortunately I seem to be getting the data in the wrong way. What am I doing wrong with the third line of the __init__? Is it because it’s a M2M?

  • 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-23T09:58:59+00:00Added an answer on May 23, 2026 at 9:58 am

    This absolutely fried my noodle (because all of this is highly counter intuitive) but I managed to come up with the following. I hope it helps someone:

    self.fields['business'].queryset = Business.objects.filter(financialproduct__id=fpID.id) 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have models similar to the following: class Band(models.Model): name = models.CharField(unique=True) class Event(models.Model):
Given the following models (cut down for understanding): class Venue(models.Model): name = models.CharField(unique=True) class
I'm working with Django 1.3, with the following 2 models: class Person(models.Model): name =
I have the following models: class Topping(models.Model): ... class Pizza(models.Model): toppings = models.ManyToManyField(Topping) I
I have the following situation: class Professor(models.Model): default_address = models.OneToOneField('Address') class Address(models.Model): name =
I have the following model: class CompanyReport(models.Model): company = models.CharField(max_length=300) desc = models.TextField() text
I'm working with models analogous to the following: class Owner < ActiveRecord::Base has_many :owned
I have the following 2 models in my Google App Engine datastore: class Search(db.Model):
Let's say I have a set of Django Models: class Article(models.Model): title = models.CharField(max_length=100,
I created a model similar to the following: class Pick(models.Model): user = models.ForeignKey(User) team

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.