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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:11:59+00:00 2026-05-25T06:11:59+00:00

I have four models in my models.py which are: models.py class Course(models.Model): course_code =

  • 0

I have four models in my models.py which are:

models.py

class Course(models.Model):
    course_code = models.CharField(max_length=100,unique=True)
    title = models.CharField(max_length=200)
    short = models.CharField(max_length=50)
    elective_group = models.CharField(max_length=100)

class Unit(models.Model):
    title = models.CharField(max_length=100)
    short = models.CharField(max_length=50)
    course = models.ForeignKey(Course)

class Pattern(models.Model):
    pattern_name = models.CharField(max_length=200)

class ExamSchedule(models.Model):
    exam_date = models.DateTimeField()
    course = models.ForeignKey(Course)
    pattern = models.ForeignKey(Pattern)
    units = models.ManyToManyField(Units)

I have all these models register with admin site, so that i can use admin functionality for these models.

My problem is when a user creates or edits a ExamSchedule object , i want the units(field) multivalue widget should contains only those values that are associated with a course as every course can have multiple units. So if user creates an Examschedule object and after selecting a course from dropdown the unit widget should only contains those units that related to the course selected.

Django-Smart-Select could have been useful but it only supports foreign key chained and grouped selects nor ManyToManyField chained select.

Thanks

  • 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-25T06:11:59+00:00Added an answer on May 25, 2026 at 6:11 am

    You can send the selected course with a Ajax request and do this to get the related units.
    Lets say you select communication networks (cn) as the course you can get the related units like so:

    cn_units = Unit.object.filter(course = 'cn').values_list('id',flat=True)
    

    This will return a single list of all the related units to that course.
    You can send this list as a response to your ajax request, iterate over this list and populate the select box for unit in ExamSchedule form. I consider plain ajax because its very flexible.

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

Sidebar

Related Questions

I have four models with the relationships Model PagetTemplate(models.Model): pass Model TextKey(models.Model): page_template =
I have two models as follows: class Tag(models.Model): # ... class Paragraph(models.Model): tags =
I'm using DjangoFullSerializers to serialize this model (into JSON): class Program(models.Model): name = models.CharField(...)
I have a model Goal that has four types of children (which all have
In my application I have a products model which has among other things four
I have four models that are related to one another, the way I have
I have four classes which share some arrangement of four properties. I have currently
I have four models: User Award Badge GameWeek The associations are as follows: User
I have a web user control which call some methods of an interface. Four
I'm using Mongoid, Devise and Rails 3.1. I have four models: Students, Teacher, Parents

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.