Skip to content

Instantly share code, notes, and snippets.

Created Mar 29, 2012
What would you like to do?
from django.db import models
class Moment(models.Model):
title = models.CharFiend(max_length=128)
image = models.ImageField(upload_to='moments')
description = models.TextField()
uploaded = models.DateTimeField(auto_now_add=True, blank=True)
def __unicode__(self):
return self.title
from django.views.generic import View
import json
from django.shortcuts import HttpResponse
from myapp.models import Moment
class MomentFeed(View):
def get(self, request, *args, **kwargs):
moments = Moment.objects.all().order_by('-uploaded') # Load all moments in reverse order
# Now convert to nice dicts for use in JSON
json_moments = []
for m in moments:
'title': m.title,
'image': m.description,
return HttpResponse(status=200, content_type='application/json', content=json.dumps(json_moments))

This comment has been minimized.

Copy link
Owner Author

@cridenour cridenour commented Mar 29, 2012

Totally untested, but point your url in to the MomentFeed (have to import it fist) to get an idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment