Need to display two different list of bellow displayed type on one Wingrid in one band . Grouping by category and showing only distinct list.
Note: 2 types have more fields that might be different but have to display only common fields
Have both types of items in a single bindable list and populate columns (UltraGridColumn) of grid programmatically (key of column - property name) for which (common) properties you need.
Related
I have a view based on a model where the user can filter the items model based on the categories field using:
Items.objects.filter(categories__in=[‘A’, ’B’, ‘C’])
However in come cases the categories field is NULL, and the user may would like to see the list of NULL and A categories. So I have tried:
Items.objects.filter(categories__in=[None, ‘A’])
But this does not see to work and my result only shows for A,B and C
This is, of course, a simplified view of the issue as the list is dynamic and there are so many other filters as well.
But the principle is the same, how can include None in the list of IN operation.
Items.objects.filter(Q(categories__in=[‘A’, ’B’, ‘C’]) | Q(categories__isnull=True))
In my template I have a field type of Droplist which maps to a Sitecore folder holding values for the Droplist which in this case is Colours. This is so that an editor cannot make a typo or invent a colour this is not in the pre-defined list.
So that colour is based off a template I call TAGS which has a single field type of 'colour' and here I create a series of items using that template to create the colours for the swatch list.
When I access the main template I duly see the colour values in that Droplist so its working as I would expect it because I can access that fields values:
tileValues.Attributes["class"] += " tile-" + Item.Fields["Tile Colour"].Value.ToLower();
However I have realized its not using the field value of the template but rather the name I have called the item. SO its just a happy mistake that its achieving the result I wanted.
However how would I obtain the actual field value for that item in the end code. I have scenarios where there will be multi lingual editors so we may name the tags as rouge, blanc etc which is what the editor will see on selection in the Droplist but we need the colour value of the field to still say red or white etc
I tried:
Item.Fields["Tile Colour"].Item.Fields["Colour"].Value
But this failed despite the API hint implying its valid.
I hope this makes sense and someone can help me obtain the actual field value and not the items name.
As Sitecore Climber wrote, don't use Droplist field type - it stores item name only and you cannot get the item itself in the code behind.
Use Droplink field type - it stores ID of the item.
Then you can get the item:
Item colourItem = Sitecore.Context.Database.GetItem(Item["Tile Colour"]);
if (colourItem != null)
{
string colour = colourItem["Colour"];
|
Can I create a calculated column that totals the record count in another list based on a field value?
Example:
List1 contains departments, each with a deptID
List2 contains employees, each assigned to a deptID
Can List1 contain a total employee count (for that deptID)?
No, this field does not exist.
You can create custom view or workflow (or maybe eventreciever) on add item in the list2, which will change corresponding field of conformity item in the list1.
But it's best just to create the custom view.
No, calculated field can refer only to fields in the same item.
I suggest you to use EventReceiver to accomplish your request. Register the receiver to the employee list with ItemAdded, ItemUpdated and ItemDeleting events. In the receiver's methods update corresponding department item and its field (number of employees).
I have a django model query that needs to fetch me the distinct rows from a particular table, but for some reason its not fetching it.
Let me know your inputs
Query
Volunteercontacts.objects.order_by('name')- gives me the expected answer ie;ordering by name
Volunteercontacts.objects.order_by('name').distinct('name')- does not eliminate the duplicate
You should differentiate between distinct Volunteercontacts models and distinct name column values.
For distinct Volunteercontacts models you can use distinct(), but in this case has no effect:
Volunteercontacts.objects.order_by('name').distinct()
For distinct columns values you can use a dictionary or array of value list:
Volunteercontacts.objects.values_list('name',
flat=True).order_by('name').distinct()
Also, remember that the ability to specify field names in distinct method is only available in PostgreSQL.
Django 1.4 provides the expected behaviour in the original question (assuming you are using Posgtres):
https://docs.djangoproject.com/en/1.4/ref/models/querysets/#distinct
I need to order_by a field comparison such that all fields matching a certain value are displayed at the top.
The SQL to do this is SELECT * FROM messages ORDER BY message='alsfkjsag' DESC
There are at least two ways to do it:
Custom SQL with UNION:
combine two selects
one who contains all rows which have your desired message
the other with all rows who have another message
Add a dynmaic Field to the QuerySet
extra(select={"is_message":"message='alsfkjsag'"})
and then order_by('is_message')
or in short:
Messages.objects.extra(select={"is_message":"message='alsfkjsag'"})
.order_by('is_message')