Added a view that return all the textures in json format

This commit is contained in:
Felipe Martín 2013-05-31 11:41:48 +02:00
parent a24be0c6f9
commit eeac0b2088
2 changed files with 11 additions and 0 deletions

View File

@ -50,6 +50,7 @@ urlpatterns = patterns('',
'blog.views.blog_item', name='blog_item'),
# Admin only
url(r'^studio/textures/$', 'studio.views.textures', name='studio_textures'),
url(r'^studio/', 'studio.views.main', name='studio_main'),
# Robots

View File

@ -1,6 +1,9 @@
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.http import HttpResponse
from database.models import Texture
from django.utils import simplejson as json
from django.core import serializers
def main(request):
@ -12,3 +15,10 @@ def main(request):
context = RequestContext(request, data)
return render_to_response('studio/main.html', context_instance=context)
def textures(request):
textures = Texture.objects.all()
data = serializers.serialize('json', textures, fields=('name', 'type', 'image',))
response = HttpResponse(data, 'application/json')
return response