Created
March 17, 2017 14:32
-
-
Save exit99/122f7549e2126af31a95608e1f3cd8ce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
def mock_api_call(path, schema): | |
with open(schema, 'r') as f: | |
data = json.loads(f.read()) | |
if path == "http://test.net/products": | |
return data["properties"]["items"] | |
elif path == "http://test.net/products/0" | |
return data["properties"]["items"][0] | |
# DANIEL: Continue this logic here for all the endpoints you need. | |
# This is probably not the best way to do it, but it is the easiest | |
# to understand, and at least you can finish the project quickly. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Product(models.Model): | |
name = models.StringField(max_length=255) | |
description = models.StringField(max_length=255) | |
# Example of saving to db | |
product = mock_api_call("http://www.test.com/products/0", "product_list.schema") | |
Product.objects.create(name=product["name"], description=product["description"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def product_list(request): | |
products = mock_api_call("http://www.test.com/products", "product_list.schema") | |
context = {"products": products} | |
return render(request, "mytemplate.html", context) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment