how to insert checkbox value to database in python - postgresql

In the front end they are selecting multiple checkboxes i.e;(district,taluk)
,so how can i get the values to the backend and how to save in the database.
note: I want to write this code based on definition not generics
this is my models
class Example(models.Model):
district = models.CharField(max_length=20)
taluk = models.CharField(max_length=20)
if we give input in json format like
{
"Bangalore" :{
"dodballapura",
" Hosakote"
}
}
then it should save in database and
in the above example bangalore is the district and remaining are talukas

Related

How to get finder input values ​from 3 datatables with the same class?

Help with datatables, I have 3 tables that have the .dataTables class, I have each table in a tab, what I want to do is obtain the values ​​entered in the search engine of each table, I investigated a function that allows me to obtain the data but this function only allows me to obtain the data of the first table, when trying to search in the others it accesses my function but it returns me this result How else could I get the result of each search engine from the 3 tables.
<empty string>
How can I get the result of each search engine from the 3 tables?
var prueba = $('.dataTableCls').DataTable();
prueba.on('search.dt', function() {
var value = $('.dataTables_filter input').val();
console.log(value);
});

how to convert map<anydata> to json

In my CRUD Rest Service I do an insert into a DB and want to respond to the caller with the created new record. I am looking for a nice way to convert the map to json.
I am running on ballerina 0.991.0 and using a postgreSQL.
The return of the Update ("INSERT ...") is a map.
I tried with convert and stamp but i did not work for me.
import ballerinax/jdbc;
...
jdbc:Client certificateDB = new({
url: "jdbc:postgresql://localhost:5432/certificatedb",
username: "USER",
password: "PASS",
poolOptions: { maximumPoolSize: 5 },
dbOptions: { useSSL: false }
}); ...
var ret = certificateDB->update("INSERT INTO certificates(certificate, typ, scope_) VALUES (?, ?, ?)", certificate, typ, scope_);
// here is the data, it is map<anydata>
ret.generatedKeys
map should know which data type it is, right?
then it should be easy to convert it to json like this:
{"certificate":"{certificate:
"-----BEGIN
CERTIFICATE-----\nMIIFJjCCA...tox36A7HFmlYDQ1ozh+tLI=\n-----END
CERTIFICATE-----", typ: "mqttCertificate", scope_: "QARC", id_:
223}"}
Right now i do a foreach an build the json manually. Quite ugly. Maybe somebody has some tips to do this in a nice way.
It cannot be excluded that it is due to my lack of programming skills :-)
The return value of JDBC update remote function is sql:UpdateResult|error.
The sql:UpdateResult is a record with two fields. (Refer https://ballerina.io/learn/api-docs/ballerina/sql.html#UpdateResult)
UpdatedRowCount of type int- The number of rows which got affected/updated due to the given statement execution
generatedKeys of type map - This contains a map of auto generated column values due to the update operation (only if the corresponding table has auto generated columns). The data is given as key value pairs of column name and column value. So this map contains only the auto generated column values.
But your requirement is to get the entire row which is inserted by the given update function. It can’t be returned with the update operation if self. To get that you have to execute the jdbc select operation with the matching criteria. The select operation will return a table or an error. That table can be converted to a json easily using convert() function.
For example: Lets say the certificates table has a auto generated primary key column name ‘cert_id’. Then you can retrieve that id value using below code.
int generatedID = <int>updateRet.generatedKeys.CERT_ID;
Then use that generated id to query the data.
var ret = certificateDB->select(“SELECT certificate, typ, scope_ FROM certificates where id = ?”, (), generatedID);
json convertedJson = {};
if (ret is table<record {}>) {
var jsonConversionResult = json.convert(ret);
if (jsonConversionResult is json) {
convertedJson = jsonConversionResult;
}
}
Refer the example https://ballerina.io/learn/by-example/jdbc-client-crud-operations.html for more details.?

Ionic 2 Storage - Adding Records

I am new to the NoSQL world and since Ionic 2 by default supports simple key-value DB, I was to some help here.
My app has a very large form. How do I go about saving new records? How do I retrieve those particular records?
Currently, to save a new record, I am doing something like this:
save(data){
let newData = JSON.stringify(data);
this.storage.set('reports', newData);
}
The problem with this is it overwrites the record instead of inserting a new record.
I am retrieving records like this:
getData() {
return this.storage.get('reports');
}
How do I go about fetching a particular record using certain values in the stored JSON?
Thanks.
What you would have to do is make reports as an array and set it to the storage.
everytime you need to insert a new record, do a
function(newData){
var some_variable = storage.get('reports'); //get Existing Table
some_variable.push(newData); //Inserts the new record to array
storage.set('reports', some_variable); //Saves report with updated data
}
For getting a particular report alone, I hope you have some id or a unique attribute y which you can distinguish a report. Assuming you have the report json as below :
var report {id : "UniqueID", name : "A sample report json"}
Then to get the report,
function(reportId){
var reports = this.storage.get('reports');//fetches your reports Array
var wantedReport = {};//Variable to store the wanted report
reports.forEach(function(r){ //Looping the array.You can use a forloop as well
if(r.id === reportId){ //filtering for the wanted reportId
wantedReport = r; // storing the report to variable
}
})
return wantedReport; //Returning the report to the caller.
}
Alternatively, If you are used to Sql and want a Sql-like way of storing these data then you can install the Sqlite cordova plugin and store your data in a Sqlite DB.

how to show list of CustomerId in dropdown list

i want to create Customer diary on the base of customerID that present in customer table.
In customerID field i want dropdown list having list of CustomerId's that are present in database
How can i do that ? can someone help me please
var _objAllCustomerIds = null;
using (AdventureWorksEntities context = new AdventureWorksEntities())
{
_objAllCustomerIds = context.MyCustomers.Select(customer => customer.Id).ToList();
}
//where AdventureWorksEntities is your DBcontent containing all your entities
//MyCustomers is the entities representation of your customer table
if this is in your .aspx file
then in your .aspx.cs file (assuming you're using code behind) you'd get the list of customer IDs and then bind that list to this dropdown.
Does this answer from another question help?
How to bind the selected value of a DropDownList

link multiple models on same row of sap.m.table

This may be a basic question, but it's my first, so please be kind :-).
I have a sap.m.table with two models, one model with transaction data (trxModel) and another model that is used to display a sap.m.select list (reasonCodeModel). The table model is set to trxModel.
The selected value key from the dropdown needs to update a value (ReasonCodeID) in the trxModel when a value from the reason code list is selected.
I can retrieve the selected key in the change event as so
var selKey = evt.getParameter("selectedItem").getKey();
Is there a simple way to find the trxModel relevant model path from the table row Select list value I've just modified? Or is it possible to bind the ReasonCodeID from the trxModel to the ReasonCodeID field in the reasonCodeModel?
Just an extra piece of info, The current row is selected and is accessible
var selItem = dtlTable.getSelectedItem();
2nd question and I guess could be kind of related, is there a way of getting the table model path based on the selected item (highlighted row) of the table? And vice a versa?
More details on Select & Table binding.
var tabTemplate = new sap.m.ColumnListItem(
{
::
new sap.m.Select(
"idReasonCodeSelect",
{
enabled : false,
change : function(evt) {
oS4View.getController().changeReasonCodeSel(evt);
}
}
),
Bind the resource code Select to the Table
// bind the reason codes to the reason code model
sap.ui.getCore().byId("idReasonCodeSelect").setModel(
oReasonCodeModel);
sap.ui.getCore().byId("idReasonCodeSelect").bindAggregation("items", "/results",
new sap.ui.core.Item({
key : "{ReasCodeID}",
text : "{ReasCodeDesc}"
}));
Per Qualiture comment, how do I bind the Select key to the table model ReasonCodeID value?
I found an approach to tackle the first part of my question above
From the change function on the Select, I can find the path of the table model using the following.
var path = evt.getSource().getParent().getBindingContext().sPath;
2nd Update:
On the selectionChange event on the table, there's a couple of options to find the associated model path or model content.
// find the model path
oModelPath = selItem.getBindingContext().getPath();
// model values
oItem = oEvent.getParameter("listItem").getBindingContext().getObject();
So my only remaining issue, While I loop through the table model results (trxModel) and I want the Select List (using setSelectedKey) to reflect the ReasonCodeID value in the trxModel.