Django rest_framework dynamic selecting other objects - sql

i want to create an Api for an order system. I have Ingredients and Products, both have categories which have to match if you want to combine them. So if a user selects a Pizza how can I only load in the ingredients which are available for Pizza, so the user cant select pasta as a Topping on his Pizza.
So if the User selects a Product pizza in extra and extraWo only the ingredients should show up, which are available for pizza
Thank you for your help

Depending on the API structure.
For example:
[
{
"Crust": "NORMAL",
"Flavor": "BEEF-NORMAL",
"Order_ID": 1,
"Size": "M",
"Table_No": 1,
"Timestamp": "2018-12-12T13:42:13.704148+00:00"
},
{
"Crust": "THIN",
"Flavor": "CHEESE",
"Order_ID": 2,
"Size": "S",
"Table_No": 5,
"Timestamp": "2018-12-12T13:42:13.704148+00:00"
},
{
"Crust": "NORMAL",
"Flavor": "CHICKEN-FAJITA",
"Order_ID": 3,
"Size": "L",
"Table_No": 3,
"Timestamp": "2018-12-12T13:42:13.720690+00:00"
}
]
Each pizza would be unique so foo[1]["Crust"] will give you "Normal". Add logic like checking the availability. Have a look at https://docs.djangoproject.com/en/3.1/topics/db/queries/#querying-jsonfield
For example do:
object.filter(pizza__normal='available')

Related

How to keep an item unique on single attribute in Redis JSON?

I have a redis JSON collection and it must to store items unique.
[
{
"name": "John",
"tId": 13,
"phone": "124",
"city":"LA"
},
{
"name": "Jane",
"tId": 14,
"phone": "256",
"city":"NYC"
}
]
In this JSON, I want to keep name unique. The other attributes can be duplicate. However, all collection must only 1 item with name John or whatever.
What kind of index do that? Do I need to use RedisBloom?

Great Expectations Row Based Dimensions

I have data like this:
[ {
"name": "Apple",
"price": 1,
"type": "Food"
},
{
"name": "Apple",
"price": 0.90,
"type": "Food"
},
{
"name": "Apple",
"price": 1000,
"type": "Computer"
},
{
"name": "Apple",
"price": 900,
"type": "Computer"
}
]
Using the Great Expectations automatic profile, a valid range for price would be 0.90 to 1,000. Is it possible to have it slice on the type dimension, so food would be 0.90 to 1 and computer would be 900 to 1000? Or would I need to transform the data first using dbt? I know the column that will create the dimension, but I don't know the particular values.
Also, same question on differences between rows. Like if they had a timestamp, instead of 900 to 1000, it validates -100 for the change in value.
I used this approach to first load the data in a pandas data frame:
https://discuss.greatexpectations.io/t/how-can-i-use-the-return-format-unexpected-index-list-to-select-row-from-a-pandasdataset/70/2

BigCommerce Stencil - Retrieve Product Custom Fields in Product Card

I'm trying to retrieve each product's custom_fields data on the category list pages in BigCommerce Stencil. This documentation here, and the JSON product representation below, would suggest this is not possible.
It is hard for me to believe this functionality would be left out of Stencil, considering it was available in Blueprint.
{
"id": 691,
"name": "Archipelago Botanicals - Pomegranate Lip Gloss",
"url": "http://******.mybigcommerce.com/archipelago-botanicals-pomegranate-lip-gloss/",
"brand": {
"name": "Archipelago Botanicals"
},
"rating": 0,
"availability": "",
"summary": "Pomegranate lip gloss leaves lips hydrated, shiny and smooth. Apply liberally.Net Weight: 0.42 oz. / 12 g Mineral Oil, Polybutene, Octyidodecanol, Butylene, Ethylene, Styrene Copolymer, Ethylene, Propylene, Styrene Copolymer, C18-36 Acid Triglycerides, Fr",
"image": {
"data": "https://cdn3.bigcommerce.com/*****/images/stencil/{:size}/products/691/41439/arbopolipgl__77026.1464267682.jpg?c=2",
"alt": "Archipelago Botanicals - Pomegranate Lip Gloss"
},
"date_added": "Apr 7th 2016",
"qty_in_cart": 0,
"pre_order": false,
"has_options": false,
"show_cart_action": false,
"price": {
"without_tax": {
"formatted": "$5.00",
"value": 5
},
"rrp_without_tax": {
"formatted": "$12.50",
"value": 12.5
},
"saved": {
"formatted": "$7.50",
"value": 7.5
},
"tax_label": "Tax"
}
},
Am I missing something, or is this functionality not available on Stencil at this time?
Has anyone come up with a creative solution to retrieve this data inside each product card?
Thanks
The product card now allows this to be exposed. It provides an array of all custom fields associated with a product. Information on the product card object is here.
It was a change that had to be made in the BC core app and the fix was released on Sept 20th

Freebase query with inner joins on the statment

Can I create an inner join on free base that uses another query?
I tried to create a join between 2 querys:
The first, select all the artist that the genre is the same as nirvana without nirvana:
[{
"id": null,
"name": null,
"name!=": "nirvana",
"type": "/music/artist",
"genre": [{
"name|=": [
"Punk rock",
"Grunge",
"Alternative rock",
"Rock music",
"Hardcore punk"
]
}]
}]
the second, select all the genre of nirvana:
[{
"name": "nirvana",
"type": "/music/musical_group",
"/music/artist/genre": []
}]
I want to create a query like this but it does not work.
[{
"id": null,
"name": null,
"name!=": "nirvana",
"type": "/music/artist",
"genre": [{
"name|=":
[{
"name": "nirvana",
"type": "/music/musical_group",
"/music/artist/genre": []
}]
}]
}]
I'm not sure why you need to do this all as one query. Since Nirvana's music spans a number of very popular genres your query will probably return thousands of results which will mean that you'll have to make multiple API requests to get all the results either way.
In any case, here's a MQL query that finds all the bands which have at least one music genre in common with Nirvana:
[{
"id": null,
"name": null,
"/music/artist/genre": [{
"id": null,
"name": null,
"!/music/artist/genre": {
"id": "/m/0b1zz",
"name": null
}
}]
}]
The exclamation mark in front of the 2nd genre property means that we want the inverse relationship ie. "music artists with this genre" instead of "music genres for this artist".
Note that I've used the MID (/m/0b1zz) to represent Nirvana. You shouldn't be using names to identify topics in a query since they're not unique. You want results for the Nirvana started by Kurt Cobain in 1987, not just any band named Nirvana.

How do i make custom reordering for products in collection in shopify

How do i make custom reorder for products in collection in shopify. i mean for exapmle i have 'test' collection and i want to reorder products in 'test' collection by using product tag i mean i put some tags like 'firstshowup' in some product in 'test' collection so when customer click 'test' collection customer see products which have 'firstshowup' tag first and then see the rest so what iam trying here is reordering using custom reordering not using like order by bestseller or allpabetically or date created s.t
thank you so much guys in advance
Your collection will be made up of Collect objects, which have a position attribute. Assuming you're using a CustomCollection, you can modify the position of the Collects by updating the CustomCollection: http://api.shopify.com/customcollection.html#update
From the examples, to update a collection, you can use:
PUT /admin/custom_collections/#{id}.json
With the following payload:
{
"custom_collection": {
"body_html": "<p>The best selling ipod ever</p>",
"handle": "ipods",
"id": 841564295,
"published_at": "2008-02-01T19:00:00-05:00",
"sort_order": "manual",
"template_suffix": null,
"title": "IPods",
"updated_at": "2008-02-01T19:00:00-05:00",
"image": {
"created_at": "2012-12-11T12:01:29-05:00",
"src": "http://cdn.shopify.com/s/files/1/0006/9093/3842/collections/ipod_nano_8gb.jpg?0"
},
"collects": [
{
"product_id": 921728736,
"position": 1
},
{
"id": 841564295,
"position": 2
}
]
}
}