Can I add a 'shortcut' link to a Django form which edits a field and saves everything? - django

I have a Django (crispy) form with many tabs which all contain many fields. Each of these tabs has an Active boolean field. The first tab of my the form contains an overview, listing all the tabs.
Now I would like to know if there is some way to have a link on that overview tab which would in theory toggle the corresponding boolean field on one of the tabs and save the result. Right now the user can go to the specific tab, check or uncheck the value and save it, but they want some sort of shortcut so they can do it in one click.
Would that be possible at all? And how could I achieve this ?
So clicking the Activate / Deactivate in this list should be the same as :
Going to the corresponding tab and checking / unchecking the available field and pressing the save button.

You can use javascript and do onchange for checkbox. In the script you can call the views to save the value to database and return to same page.

Related

How to fill dynamic form fields using capybara

I have a form that contains a select box and a text field.
The text field is displayed dynamically based on the selectbox selection. If the value of selectbox is "Yes", then the text field will be displayed and vice versa.
I am running an rspec test and filled the select box value with "Yes"
select 'Yes', from: 'property[have_water_bills]'
Now i want to fill a value on the text field
fill_in 'property[irrigation_cycle_count]', with: 5
But i am getting the following error.
Capybara::ElementNotFound:
Unable to find field "property[irrigation_cycle_count]"
That is, capybara cannot find the dynamic element. Does anyone know how to fix this?
Poltergeist doesn't gemerate a click event when choosing an item from a select. It generates a focus on the option, change on the select, blur on the option. It is more like if a user selected the option with keyboard instead of using a mouse. You probably should be doing the logic to display your text field on the change event anyway so that it works if people use a mouse or a keyboard to navigate around your page. It also makes more sense to run your show/hide logic on the change event because that's what you actually care about, not clicks.
Finally got this to work using the following piece of code
page.execute_script("$('#have_water_bills').val('true').trigger('click')")

django model attribute edit & save with no extra page

I rende certain objects values in django template in a form of a table.
I let user to edit the value and save the edit so I can track the history of edit.
At the moment I use django forms to let user do single object attribute value OR chosen objects attribute values OR all of them and save it.
My problem is with forms is that the way it works at the moment is:
user clicks a value in 'main' page so it links to object 'edit' page in which I return a form so user can edit it.
The problem is with that extra url or extra page. I do not want to do it via separate pages.
I would like to click on the object (like in the excel) and change the value there in 'main' page and submit the edits from the same page.
How can I achieve it with django ?
Can somebody point me into right direction and point out what I should read about to understand it or how I should do it ?
I want to edit either single or let user edit multiple objects values and save the changes and still be able to track the history of edits / changes.
You should look into modals. So when a user clicks to edit it will display a pop-up that you can render the form in without leaving the page.

How can i have both read only and editable fields in django administration?

I have a table which contains some information.
For example, I have two options like View and Edit. I will give Edit option for X info and View option for Y info on a table. I will make my options as a link so that I can able to click on the options.
Now, what I want to happen when I click on Edit is to display what Django admin normally has. When I click on View, I want info of that particular line to display as a non editable field.
I have already tried this but it is making both options read only fields.
Is this possible?

Django multi-select widget. Add arbitrary select components

i would like to make a widget that lets the user select a value from a drop-down list and then add new drop-down lists with values filtered based on the previous selections. I don't know where to start from....
If the amount of drop-downs is finite and determinable by the time you develop the software (e.g. selecting country->city->street) I would suggest to:
add all the extra dropdowns (without data yet) to your form, make sure they are hidden
use jqueryui to un-hide and populate the dropdowns as needed using ajax
Don't forget to disable/hide the whole form by default and only show it if JS is enabled in browser.
Also, you will of course need another view, with which only ajax speaks.
Here for you to catch the idea how the stuff should work. Sorry don't know if they have anything more similar. But: user selects something -> jquery requests data for the next dropdown -> jquery displays next populated dropdown.

Django - Dynamically assign initial value to form from other fields

I'm creating a Django app. I would like to know it it's possible (I haven't seen anywhere that it is) to create a form which has initial values that can change depending on selections in other fields. To be more specific, I have a field which is a drop-down menu of standard cosmologies, each of which has a certain set of parameters. These parameters are fields of their own. I want to set the initial values of these parameters after the user has selected a specific option from the drop-down menu. If possible, they should also be greyed out (ie. not changeable) when this is done (there is one option in the dropdown which is 'Custom', for which they should be editable).
I hope that's enough information. Cheers.