Update Context

Hi Everyone, I am trying to build dynamic page registration.
this is the user story:
1)user put his name
2) user put is email
4) user pick Main Class
5) user picks 3 submain class.

I am trying to make the 4) to be dynamic,
when someone picks the main class from a list of buttons
(i use jquery to change the select field(char field with choices), it will filter the submain objecst with only objects related to that main class.

here is my view:

 def home(request):
            form=StudentForm(request.POST or None)
            mains= Speciality.objects.all() #the main class
            subs=Submain.objects.all() #the sub class
            if form.is_valid():
            return render(request,"formmate/main.html",context)

so I just want the “subs” to change without refreshing the web or load other pages.

Last Example:
Main Class: (alot of buttons with names)>>> jquery will change the list, list is “display:none”.

subclass: alot of buttons with subclass with no filter related to the main class.

in my html page, i have a for loop of subs.
so how can i make the context to change ?
could not find ajax or jquery similer problem.

thank you!

What we have done in the past is assign an action to the main groupings that triggers an AJAX call back to the server.
This involves writing a JavaScript function to issue the get request from the server, passing the main’s id as a parameter, to a view on the Django side. The Django view then queries the sub class based on that ID, and renders a template for the button list. It then inserts that rendered template into a dict which is then returned as a JSON response back to the caller.

ok thank you i got it working,
i have one problem:

the red one not working for me and i need the attirbute and not the id of the forgin key,
how can do that ?
thank you.

That’s up to the view to provide. You need to ensure that the name is sent out to the client.

ok thank you. i will post answer soon.