Skip to content

Instantly share code, notes, and snippets.

@hschmitt
Created May 4, 2012 21:33
Show Gist options
  • Save hschmitt/2597873 to your computer and use it in GitHub Desktop.
Save hschmitt/2597873 to your computer and use it in GitHub Desktop.
9 from django.conf import settings
86 def recipes(request, wine_id):
87 """
88 Returns a list of recipes recommended for a wine.
89 """
90 # Grab the wine from the database
91 wine = get_object_or_404(Wine.objects.current(), id=wine_id).
92 # Start building the document
93 document = OrderedDict()
94 ....
95 # Recipes
96 document['recipes'] = []
97 for recipe in wine.recipes.all():
98 recipe_subdoc = OrderedDict()
99 recipe_subdoc['id'] = recipe.id
100 recipe_subdoc['name'] = recipe.name
101 recipe_subdoc['picture'] = recipe.imageset.get_picture_url(
102 'pic_1600x700'
103 )
104 document['recipes'].append(recipe_subdoc)
109 # Sending the document to the browser
110 response = json_response(request, document)
114 return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment