Django database query to select all values in a column - django

Basicly I just want to say "give me all the values from column Y" and not "select all values and filter for Y based on primary key Z"
The word "column" is only mentioned one time on the Django documentation page and the "primary key" and "row" options are very clearly explained in my eyes.
Now I wonder, how do I do this? :)

If I understand well, you want to query values for only a column, I think this is what you need:
MyModel.objects.values('column_name')
Or if you want to get a list of values:
MyModel.objects.values_list('column_name', flat=True)
You can apply any filter before selecting values:
MyModel.objects.filter(**criteria**).values_list('column_name', flat=True)

Related

How can I search for primary key in APEX Interactive grid search page field?

How can I search by primary key value in APEX interactive grid ,
by default the search page can search all text columns only , but I need to search by primary key also for example ORDER_ID .
I checked the page and region attributes but I didn't find the way to change the query and search for primary key in the query .
One option is to add another column to the query.
It seems that the primary key column is a number. Apply TO_CHAR function to it and it'll appear as text column and will thus be searchable.
Something like this:
select empno, --> primary key
to_char(empno) as text_empno, --> TO_CHAR applied to the PK column
ename
from emp
How does it look like?

How to create a field with a list of choices but store the index?

I'm making a Microsoft Access table where one of the fields is a list of pre-made options. When I make a SQL query on that table it returns the values of the list as strings containing the spelled out choice. I would like to assign numerical values to each element of the list so a SQL query returns a number instead. How do I do this? I know it's possible because I have an access file with such a list but I'm unable to recreate it.
An easy way to do this is to have your combo box use a query of the table as a Rowsource. This query would have the table unique ID in the first field and the field you wish to return as the second field. Then change the setting on the combo box for "Column Count" to 2. If you want to show both fields change the "Column Widths" value to 1"; 1". If you want to show only one field, change the value of one you do not want to see to 0. Now we you refer to this list in an SQL queries, it will use the ID field but show the user the string field.

Editable Fields in Interactive Grid

I have a column that needs to be editable by user in interactive grid.
However, I want that user can only choose from 2 static values. Is there a way I can implement that?
Use a 'Select List' or 'Switch' for column type, instead of 'Text Field'.
Then associate the relevant List of Values, either from a static list, a SQL query, or pre-defined shared component.
Alternatively/additionally, you could have a validation on that column to check for those specific values.
You can convert column type to "Select List" or "Radio Group", and then you can define "Static Values" as "List of Values".

How to make a existing column "unique" in PowerBI, so I can form a "one-to-many" relationsship?

I have 40 tables. One table has 20 rows, and one of the columns have 1385 distinct values.
I would like to use this in a relationship with another table.
TableName(1385 rows) Column:Name:(1385 distinct values)
But when I try to do this in Powerbi/Manage-Relations, it will only accept the option "Many-to-Many" relationship. It reports that none of the column are "Unique".
Well, the data in the column is unique. So how can I configure this column to be unique so I can use it in a "One-to-Many" relationship"?
Do I have to edit the DAX expression and put the "DISTINCT" keyword in the expression for that column? And How?
Now I have:
}, {"Columnname", Int64.Type}, {
what you can try is to perform remove duplicates in that table(i know its already contains distinct values but you can give it a try)... and/or just load the data again.
Best way would be when you group your data in the query editor. This way your table has only distinct values and you can create your relationship.
In the query designer under Home > Group By you can group after your column.
Example
Table:
Table (2):
Relationship (One to Many):
Result:
I hope this helps.

Order by a field which isn't included on a matrix POWERBI

I'm trying to build a matrix on PowerBI and I want to order the data by a field which I don't want to include in the matrix. My field named "category" in the matrix must be on a especific order, and I create a numeric field to specify the order. But when I want to order by that numeric field, I can't, PowerBI only allows me to order by the field which is in the matrix.
To test it, I concatenated my numeric field with the category like this: numeric - category, and it works, but I don't want to show it like that, I want only the category field order by the numeric field.
Any suggestion? Thanks.
EDIT:
I have also tried with "Sort by column", but neither selecting the matrix nor the data source table, the button is not activated.
Also detail that "category" has 2 or more numbers in "order" column.
"Sort by column" was not activated because there were many duplicated rows in "Category" field, so I couldn't sort by "Order" because 2 or more rows share the same "category" with different "Orders". I fixed my database and now I can use the tool.