Related
In one colomn response is store like this :-
I have this model.py:
class Form(models.Model):
id = models.CharField(max_length=100, blank=True)
children = models.JSONField(null=True, blank=True)
this is my views.py file:
class FormAPIView(APIView):
def get(self, request):
queryset = Form.objects.all()
queryset = queryset.filter(children__contains=[{"id": "propertyName#0"}])
I have tried this , but didn't get expected output
Now i want to filter this response
[
{
"id": "A",
"children": [
{
"id": "propertyName#0",
"index": 0,
"label": "Property",
},
{
"id": "userName#0",
"index": 1,
"label": "Reported By",
},
{
"id": "textinput#0",
"index": 2,
"label": "Reported By Title",
},
{
"id": "dateinput",
"index": 3,
"label": "Date Reported",
}
],
"component": "sectionDivider"
},
{
"id": "B",
"children": [
{
"id": "propertyName#0",
"index": 0,
"label": "Property",
},
{
"id": "userName#0",
"index": 1,
"label": "Reported By",
},
{
"id": "textinput#0",
"index": 2,
"label": "Reported By Title",
},
{
"id": "dateinput",
"index": 3,
"label": "Date Reported",
}
],
"component": "sectionDivider"
},
{
"id": "C",
"children": [
{
"id": "propertyName#0",
"index": 0,
"label": "Property",
},
{
"id": "userName#0",
"index": 1,
"label": "Reported By",
},
{
"id": "textinput#0",
"index": 2,
"label": "Reported By Title",
},
{
"id": "dateinput",
"index": 3,
"label": "Date Reported",
}
],
"component": "sectionDivider"
}
]
I want to filter like this
how can i get this response
I have id for the check like id: "A", id :"B" should only filter A and B and inside A and B i also want to filter.
[
{
"id": "A",
"children": [
{
"id": "propertyName#0",
"index": 0,
"label": "Property",
}
],
"component": "sectionDivider"
},
{
"id": "B",
"children": [
{
"id": "propertyName#0",
"index": 0,
"label": "Property",
},
{
"id": "userName#0",
"index": 1,
"label": "Reported By",
}
],
"component": "sectionDivider"
}
]
Till now i have tried django orm but unable to get expected output
Django ORM does provide support for nested queries inside the JSONField.
Assuming your JSON field is defined like this:
class SomeModel(models.Model):
....
parent = JSONField()
The desired results can be achieved by using the ORM and the contains lookup:
SomeModel.objects.filter(
parent__contains=[{"id":"A", "children": [{"label": "Property"}]}, {"id":"B"}]
)
It's quite powerful and allows you to do nested filtering as well.
See how I used the children:label filter along with the id filter.
NOTE: this question is specifically for support staff of the HERE Developer API because they ask freemium users to post support questions on Stack Overflow rather than trying to contact them directly. If you're not a member of their staff and you're unable to help or if the question is unclear to you, don't worry about it. :)
For some reason the /discover endpoint doesn't return the "Buffalo Exchange" place that's at my specified coordinates, but only returns 2 localities that are much further away. This is the query that I'm using: https://discover.search.hereapi.com/v1/discover?at=34.003975%2C-118.484823&q=Buffalo&limit=20&apiKey=<insert API KEY>. These are the results I currently receive:
{
"items": [
{
"title": "Buffalo, NY, United States",
"id": "here:cm:namedplace:21018816",
"resultType": "locality",
"localityType": "city",
"address": {
"label": "Buffalo, NY, United States",
"countryCode": "USA",
"countryName": "United States",
"stateCode": "NY",
"state": "New York",
"county": "Erie",
"city": "Buffalo",
"postalCode": "14202"
},
"position": {
"lat": 42.88544,
"lng": -78.87846
},
"distance": 3551940,
"mapView": {
"west": -78.9168,
"south": 42.82603,
"east": -78.79492,
"north": 42.96651
}
},
{
"title": "Buffalo City, Eastern Cape, South Africa",
"id": "here:cm:namedplace:23402337",
"resultType": "locality",
"localityType": "city",
"address": {
"label": "Buffalo City, Eastern Cape, South Africa",
"countryCode": "ZAF",
"countryName": "South Africa",
"state": "Eastern Cape",
"county": "Buffalo City",
"city": "Buffalo City",
"postalCode": "5201"
},
"position": {
"lat": -33.0148,
"lng": 27.9038
},
"distance": 16910944,
"mapView": {
"west": 27.15745,
"south": -33.28749,
"east": 28.08053,
"north": -32.674
}
}
]
}
You can see that for both places the resultType is "locality".
Now compare that to the first result of a similar query that searches for the term "Exchange" instead of "Buffalo". All other query params are the same. This is the URL: https://discover.search.hereapi.com/v1/discover?at=34.003975%2C-118.484823&q=Exchange&limit=20&apiKey=<insert API KEY>, and this is how the results begin (not shown fully because there are many results):
{
"items": [
{
"title": "Buffalo Exchange",
"id": "here:pds:place:8403fv6k-b15f290ec4f409deea99318f7388bbd6",
"resultType": "place",
"address": {
"label": "Buffalo Exchange, 2449 Main St, Santa Monica, CA 90405, United States",
"countryCode": "USA",
"countryName": "United States",
"stateCode": "CA",
"state": "California",
"county": "Los Angeles",
"city": "Santa Monica",
"district": "City of Santa Monica",
"street": "Main St",
"postalCode": "90405",
"houseNumber": "2449"
},
"position": {
"lat": 34.00342,
"lng": -118.48483
},
"access": [
{
"lat": 34.00331,
"lng": -118.48493
}
],
"distance": 61,
"categories": [
{
"id": "600-6800-0090",
"name": "Women's Apparel",
"primary": true
},
{
"id": "600-6800-0000",
"name": "Clothing & Accessories"
},
{
"id": "600-6800-0089",
"name": "Men's Apparel"
},
{
"id": "600-6900-0251",
"name": "Used/Second-hand Merchandise Stores"
}
],
"references": [
{
"supplier": {
"id": "core"
},
"id": "1211447153"
},
{
"supplier": {
"id": "yelp"
},
"id": "5PzeN6hGLBPmJpCJ2ZmfCQ"
}
],
"contacts": [
{
"phone": [
{
"value": "+13103147300"
},
{
"value": "+13103924301",
"categories": [
{
"id": "600-6800-0000"
}
]
}
],
"fax": [
{
"value": "(520) 622-7015",
"categories": [
{
"id": "600-6800-0000"
}
]
}
],
"www": [
{
"value": "http://www.buffaloexchange.com",
"categories": [
{
"id": "600-6800-0000"
},
{
"id": "600-6900-0251"
}
]
}
],
"email": [
{
"value": "contact#bufex.com",
"categories": [
{
"id": "600-6800-0000"
}
]
}
]
}
],
"openingHours": [
{
"categories": [
{
"id": "600-6800-0000"
}
],
"text": [
"Mon-Sun: 11:00 - 20:00"
],
"isOpen": false,
"structured": [
{
"start": "T110000",
"duration": "PT09H00M",
"recurrence": "FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA,SU"
}
]
},
{
"categories": [
{
"id": "600-6800-0090"
},
{
"id": "600-6900-0251"
}
],
"text": [
"Mon-Sat: 11:00 - 20:00",
"Sun: 11:00 - 19:00"
],
"isOpen": false,
"structured": [
{
"start": "T110000",
"duration": "PT09H00M",
"recurrence": "FREQ:DAILY;BYDAY:MO,TU,WE,TH,FR,SA"
},
{
"start": "T110000",
"duration": "PT08H00M",
"recurrence": "FREQ:DAILY;BYDAY:SU"
}
]
}
]
},
...
}
You can see that the first result has the name "Buffalo Exchange" and the "resultType" is "place". This is the result I want. The question is why does this result fail to show up when the search query is "Buffalo"? Of course with the /discover endpoint I can't specify the category IDs I want to search, that's only available via the /browse endpoint. But with the /browse endpoint I can't specify a specific search term like "Buffalo" or "Exchange".
Update: this problem also happens with the "Bison" query in Alberta, Canada. The query for this is https://discover.search.hereapi.com/v1/discover?at=56.745531%2C-111.351341&q=Exchange&limit=20&apiKey=<insert API KEY>. This query yields only 10 results, and only 4 of them have resultType of "place".
We recommend application developers to use both Autosuggest and Discover, you get the nearby Buffalo Exchange because Autosuggest considers that the query is incomplete. Note that Discover considers the query to be complete.
As HERE Geocoding and Search is meant to provide relevant responses to user queries.
Geocoding Search Api (Autosuggest): https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-autosuggest-brief.html
Geocoding Search Api (Discover): https://developer.here.com/documentation/geocoding-search-api/dev_guide/topics/endpoint-discover-brief.html
The above-mentioned user guide can help modify the query for accurate results.
I have posted data(ex:title field) in different languages, when i try to filter the data in get request it is giving empty result
GET /rails:
My get request result is :
[
{
"id": 1,
"type": "channel",
"filter": [
1
],
"data": [
1
],
"status": 0,
"rows": 0,
"title": "string"
},
{
"id": 2,
"type": "appgg",
"filter": [
2
],
"data": [
2
],
"status": 1,
"rows": 2,
"title": "ಚಲನಚಿತ್ರ"
}
]
GET /rails?title=string
it is giving proper result:
[
{
"id": 1,
"type": "channel",
"filter": [
1
],
"data": [
1
],
"status": 0,
"rows": 0,
"title": "string"
}
]
when i try to filter title data other than english i am getting empty result
GET /rails?title=ಚಲನಚಿತ್ರ:
expected result :
[
{
"id": 2,
"type": "appgg",
"filter": [
2
],
"data": [
2
],
"status": 1,
"rows": 2,
"title": "ಚಲನಚಿತ್ರ"
}
]
Actual result:
[]
when I try to print request params in my django views like below:
title = self.request.query_params.getlist('title',None)
print(title)
I am getting the following log:
title filter �²¨�¿¤Í°
Django is unable to identify the language I am passing, How can I add multi-language support in Django?
Thanks
Here is the form model schema:
{
"startTime": "",
"stopTime": "",
"id": "objectid",
"formQuestions": [
{
"type": 0,
"label": "",
"content": [
""
],
"id": "objectid"
}
]
}
relations of form.json:
"relations": {
"questions": {
"type": "embedsMany",
"model": "FormQuestion",
"option": {
"validate": true,
"autoId": true
}
}
}
If I post to http://localhost:3000/api/Forms as follow,
{
"startTime": "",
"stopTime": "",
"formQuestions": [
{
"type": 0,
"label": "a label",
"content": ["the content"]
}
]
}
it returns:
{
"startTime": "",
"stopTime": "",
"id": "54ccf7ae6159f1bc0bc6b430",
"formQuestions": []
}
But I want the embedded model formQuestion also to be inserted into the database, how can I do it? I would be grateful if anyone could help me.
Nobody knows, but I find the way myself.
It is because there is some bug about auto id generating with embedded document. It is useless even I set autoId to true. So if I post with manual id, it will success.
Just like this:
{
"startTime": "",
"stopTime": "",
"formQuestions": [
{
"id": 1,
"type": 0,
"label": "a label",
"content": ["the content"]
}
]
}
My application creates posts on user's wall, but it's marked as link.
I see that other applications doing same thing but for some reason facebook don't mark their posts as links. Tried to find the difference between them and me in graph api explorer, and the only difference is status_type attribute (this is not even documented). Mine set to "shared_story" and in other applications is "app_created_story". Tried to set it manualy but facebook still use shared_story even if I set it to app_created_story
Data from graph api explorer (first is my application)
[{
"id": "100001302536317_168939309896943",
"from": {
"name": "Андрей Реаскович",
"id": "100001302536317"
},
"story": "Андрей Реаскович shared a link.",
"story_tags": {
"0": [
{
"id": "100001302536317",
"name": "Андрей Реаскович",
"offset": 0,
"length": 16,
"type": "user"
}
]
},
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=AQBcrRQnipKHB6g6&w=90&h=90&url=http%3A%2F%2Fstatic.jackpotrush.com%2Fimages%2Fviral%2Fgames%2Fjoker_jester.png",
"link": "http://apps.facebook.com/jackrush/?ref=bonus-game",
"name": "I Won Big on a Bonus Round at Jackpot Rush!",
"caption": " ",
"description": "I Just Won 200 Coins at a Jackpot Rush Bonus Round and it Feels Amazing!",
"icon": "http://static.ak.fbcdn.net/rsrc.php/v2/yD/r/aS8ecmYRys0.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100001302536317/posts/168939309896943"
},
{
"name": "Like",
"link": "http://www.facebook.com/100001302536317/posts/168939309896943"
}
],
"privacy": {
"description": "Only Me",
"value": "SELF"
},
"type": "link",
"status_type": "shared_story",
"application": {
"name": "Jackrush Development",
"namespace": "jackrush",
"id": "434595133235542"
},
"created_time": "2012-11-12T08:48:18+0000",
"updated_time": "2012-11-12T08:48:18+0000",
"comments": {
"count": 0
}
},
{
"id": "100001302536317_420171444702936",
"from": {
"name": "Андрей Реаскович",
"id": "100001302536317"
},
"picture": "http://platform.ak.fbcdn.net/www/app_full_proxy.php?app=242829452408559&v=1&size=z&cksum=cd0fa7a15202d05700bf1464fd989d42&src=http%3A%2F%2Fc.cdn.blueshellgames.com%2Fs%2F%3Aac05b878%2Fmonte%2Fi%2Ffeed_story_image-logo_black.png",
"link": "http://apps.facebook.com/luckyslotsgame/?action=shareLevelUpReward&posterID=fb%3A100001302536317&k_utag=df3f4636aabab65e&levelUpToken=6553%3AsVFCJmW43zW_Nni9vBB9xg%3D%3D&level=4&refID=fb%3A100001302536317&utm_medium=viral&utm_source=levelUp",
"name": "First 5 Clickers get 150 Free Coins!",
"caption": "Андрей just reached level 4 and is giving away 150 Free Coins to celebrate!",
"description": "Play the best slots on Facebook! Get free chips daily! Unlock new slot machines and new bonus games! Don't miss out, play now!",
"icon": "http://photos-d.ak.fbcdn.net/photos-ak-snc7/v85006/51/242829452408559/app_2_242829452408559_9481.gif",
"actions": [
{
"name": "Comment",
"link": "http://www.facebook.com/100001302536317/posts/420171444702936"
},
{
"name": "Like",
"link": "http://www.facebook.com/100001302536317/posts/420171444702936"
},
{
"name": "Claim BONUS Coins",
"link": "http://apps.facebook.com/luckyslotsgame/?action=shareLevelUpReward&posterID=fb%3A100001302536317&k_utag=df3f4636aabab65e&levelUpToken=6553%3AsVFCJmW43zW_Nni9vBB9xg%3D%3D&level=4&refID=fb%3A100001302536317&utm_medium=viral&utm_source=levelUp"
}
],
"privacy": {
"description": "Public",
"value": "EVERYONE"
},
"type": "link",
"status_type": "app_created_story",
"application": {
"name": "Lucky Slots",
"namespace": "luckyslotsgame",
"id": "242829452408559"
},
"created_time": "2012-11-12T08:13:25+0000",
"updated_time": "2012-11-12T08:13:25+0000",
"comments": {
"count": 0
}
}]