Django-Tastypie filter all fields - tastypie

I'm doing a project with django-tastypie and know how to set a field to filter by, thus:
filtering = {
'nationality': ALL,
}
What I want to know is if there was some setting that would allow me to have all the fields available for filtering, without having to be set one by one as in the example above?
Someone can help me?

Unfortunately, I Don't think there is a way to do it at once.
You can use this way,
for field in YourModel.__dict__['_meta'].fields:
filtering.update({field.name : ALL})

Related

How can I create a list with letters as headers?

I want to make a list of currencies in alphabetical order with letters as headers. Please have a look at the pictures for better understanding.
This is what I want to achieve
The list I have been able to achieve so far (A simple one)
I searched for packages but I couldn't find anything as per my need. Your help would be much appreciated.
Thanks.
Sounds like: how to implement Alphabet scroll in flutter
another options is: You can make a Map for example
countriesDict = {"a" : {"Algeria, Andorra", "b" : {"Bolivia, Bosnia ...."}}}
and retrieve it it in your code. For example:
for (country in countriesDict) {
... Your code to sort it out
}
and then display it.
You can use this package to implement your desired result easily.
Grouped List
Rest of it depends on your design.

How can you filter search by matching String to a field in Algolia?

I'm trying to create filters for a search on an Android app where a specific field in Algolia must exactly match the given String in order to come up as a hit. For example if Algolia has a field like "foo" and I only want to return hits where "foo" is equal to "bar", then I would expect that I would have to use a line of code like this:
query.setFilters("foo: \"bar\"");
Any guesses as to why this isn't working like I see in the examples or how to do so?
Ah, I thought that attributesForFaceting was done by setting what was searchable or not. It was on a different page within the dashboard than I was previously using. Thanks #pixelastic.

In selector with asterisk * not working in report selection

What is the proper way to search a table for every record that starts in a similar way? I have tried:
"THESE. WORDS" IN {example_one.job_title} and {example_two.status} = "A"
But I need all combinations, including "THESE. WORDS*" Adding the asterisk doesn't work, I guess because of how IN works.
To summarize information in the comments,
to limit job_title by the list of values in these. words, you need your field on the left hand side and the values on the right.
you may want {example_one.job_title} LIKE 'keyword*'
If you found this information helpful, you can upvote and/or accept the answer.

ElasticSearch - filter terms for autocomplete

I would like for an autocomplete to get the terms starting with some specific characters.However, the terms returned do not begin with the specified text ("wer" in this case), and more than that, no matter what the prefix content is, they are always the same. The query I am using now is:
{"facets":
{"count":
{"terms":
{"field":"content"},
"facet_filter":
{"prefix":{"content":"wer"}}
}
},
"size":0
}
I am wondering what am I missing or doing wrong. Any help much appreciated. Thanks!
Perhaps you miss a "query" entry after the facet_filter.
If this does not help try regex pattern for facets, but be aware that facets will be removed in future updates of elasticsearch.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-facets-terms-facet.html#_regex_patterns

Web2py - Multiple tables read-only form

I've searched around the web for a way to achieve this, and found multiple solutions. Most of them had messy code, all of them drawbacks. Some ideas involved setting default values of all the db fields based on a record. Others worked by appending multiple SQLFORMs, which resulted in differences in indentation on the page (because it's 2 HTML tables in 1 form).
I'm looking for a compact and elegant way of providing a read-only representation of a record based on a join on two tables. Surely there must be some simple way to achieve this, right? The Web2py book only contains an example of an insert-form. It's this kind of neat solution I am looking for.
In the future I will probably need multi-table forms that provide update functionality as well, but for now I'll be happy if I can get a simple read-only form for a record.
I would greatly appreciate any suggestions.
This seems to work for me:
def test():
fields = [db.tableA[field] for field in db.tableA.keys() \
if type(db.tableA[field]) == type(db.tableA.some_field)]
fields += [db.tableB[field] for field in db.tableB.keys() \
if type(db.tableB[field]) == type(db.tableB.some_field)]
ff = []
for field in fields:
ff.append(Field(field.name, field.type))
form = SQLFORM.factory(*ff, readonly=True)
return dict(form=form)
You could add in field.required, field.requires validtaors, etc. And also, since you're using SQLFORM.factory, you should be able to validate it and to updates/inserts. Just make sure that the form you are building using this method contains all of the necessary information to validate the form for update -- I believe you can add them easily to the Field instantiation above.
EDIT: Oh yeah, and you need to get the values of the record in question to pre-populate the form based on a record id (after form is defined)... also.. I just realized that instead of those list comprehensions, you can just use SQLFORM.factory and provide the two tables:
def test():
form = SQLFORM.factory(db.tableA, db.tableB, readonly=True)
record = ... (query for your record, probably based on an id in request.args(0))
for field in record.keys():
if (*test if this really is a field*):
form.vars[field] = record[field]
return dict(form=form)
Some tweaking will be required since I only provided psuedo-code for the pre-population... but look at: http://web2py.com/books/default/chapter/29/7#Pre-populating-the-form and the SQLFORM/SQLFORM.factory sections.