Find records in a Extjs Store for which displayValue starts with a specific substring - regex

I am trying to fetch records from ExtJS store which start with specific substring.
e.g. If I have a country store and if I have a string 'IN' then I want records of India and Indonesia from store.
Is there any way to do this?
Thanks

I suppose this is about a combobox, so that's the default behavior.
For example: https://fiddle.sencha.com/#fiddle/11r4
If you just want to filter a store, look at:
filters config - Array of Filters for this store.
filter method - Filters the data in the Store by one or more fields.
filterBy method - Filters by a function.
Ext.util.Filter - Represents a filter that can be applied to a MixedCollection.

Related

Django - How to gruouping column datatble in django?

I have script for my datatable. So, I store my attribute from API and I need to grouping column into one column. Can django do that? As long I know, that could but in JQuery, but it's impossible to bring my datatable to JQuery basics so many attributes.
Here is my code :
['No. Telp <br/>Nasabah 1','notelp1_debitur',''],
['No. Telp <br/>Pasangan 2','notelp2_pasangan',''],
['No. Telp <br/>Pasangan 1','notelp1_pasangan',''],
['No. Telp <br/>Nasabah 2','notelp2_debitur',''],
And I want to be grouping it like this :
Thanks in advance.
this is not related to django or any other backend frameworks how we are gonna show the data in frontend.
this is the html table, and how to put data in that table to create something like the photo.
you could create a table, or two.
for a cell of html table you could specify the col(s), and row(s) it needs to capture. read about this on w3schools.com

Query Django's HStoreField values using LIKE

I have a model with some HStoreField attributes and I can't seem to use Django's ORM HStoreField to query those values using LIKE.
When doing Model.objects.filter(hstoreattr__values__contains=['text']), the queryset only contains rows in which hstoreattr has any value that matches text exactly.
What I'm looking for is a way to search by, say, te instead of text and those same rows be returned as well. I'm aware this is possible in a raw PostgreSQL query but I'm looking for a solution that uses Django ORM.
If you want to check value of particular key in every object if it contains 'te', you can do:
Model.objects.filter(hstoreattr__your_key__icontains='te')
If you want to check if any key in your hstore field contains 'te', you will need to create your own lookup in django, because by default django won't do such thing. Refer to custom lookups in django docs for more info.
As far as I can remember, you cannot filter in values. If you want to filter in values, you have to pass a column and value you are referencing to. When you want it to be case insensitive use __icontains.
Although you cannot filter by all values, you can filter by all keys. Just like you showed in your code.
If you want to search for 'text' in all objects in key named let's say 'fo' - just do smth like this:
Model.objects.filter(hstoreattr__icontains={'fo': 'text'})

Django create date list from existing objects

i come with this doubt abobt how to make a linked dates list based on existing objects, first of all i have a model with a DateTimeField which stores the date and hour that the object was added.
I have something like:
|pk|name|date
|1|name 1|2016-08-02 16:14:30.405305
|2|name 2|2016-08-02 16:15:30.405305
|3|name 3|2016-08-03 16:46:29.532976
|4|name 4|2016-08-04 16:46:29.532976
And i have some records with the same day but different hour, what i want is to make a list displaying only the unique days:
2016-08-02
2016-08-03
2016-08-04
And also because i'm using the CBV DayArchiveView i want to add a link to that elements to list them per day with a url pattern like this:
url(r'^archive/(?P<year>[0-9]{4})/(?P<month>[-\w]+)/(?P<day>[0-9]+)/$', ArticleDayArchiveView.as_view(), name="archive_day"),
The truth is that i don't have a clue of how to achieve that, can you help me with that?
Extracting unique dates
instances = YourModel.objects.all()
unique_dates = list(set(map(lambda x: x.date.strftime("%Y-%m-%d"), instances)))
About listing them, your url pattern looks ok. You need to define a view in order to retrieve them and wire up with that url.
UPDATE:
If you want to order them, just:
sorted_dates = sorted(unique_dates)

Django, how to filter for a range of rows then pick the one with max date?

Goal:
In here I am filtering for deals with the given id and from those I would like to pick the one with the latest date.
contact.deal_set.filter(deal_id=deal_id).aggregate(Max('deal_start_datetime'))
However this only gives back a dictionary with the max date in it. I need the row though.
What am I doing wrong?
Use the .latest method provide for django query sets.
For example in your particular case:
contact.deal_set.filter(deal_id=deal_id).latest('deal_start_datetime')
Django Documentation: https://docs.djangoproject.com/en/dev/ref/models/querysets/#latest
Use this
contact.deal_set.filter(deal_id=deal_id).order_by('-deal_start_datetime')
This will sort queryset by deal_start_datetime in reverse, 0th element is the latest one, you can get it as
latest_contact = contact.deal_set.filter(deal_id=deal_id).order_by('-deal_start_datetime')[0]

Filtering in django admin using address bar

Suppose I have a model Order, which has a column num -- an order number. Now I want to filter several rows from this model in admin view. Having 1 value, I do:
http://bla-bla-bla/admin/app/order/?num__exact=11534
How can I do this when I have several values?
Or should I use queryset()? How then I should send a list of values to request?
in should work, try this in the url
http://bla-bla-bla/admin/app/order/?num__in=11534,11535,11536
Don't forget that whatever you put in the query string has to be allowed for the admin interface. You can't put in filters that weren't defined there - ever since this security release https://www.djangoproject.com/weblog/2010/dec/22/security/