public
Last active

A quick example using neo4django with tastypie adapted from the tastypie tutorial (http://django-tastypie.readthedocs.org/en/latest/tutorial.html).

  • Download Gist
api.py
Python
1 2 3 4 5 6 7
from tastypie.resources import ModelResource
from .models import Entry
 
class EntryResource(ModelResource):
class Meta:
queryset = Entry.objects.all()
resource_name = 'entry'
models.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
from neo4django.auth.models import User
from neo4django.db import models
from django.template.defaultfilters import slugify
 
class Entry(models.NodeModel):
user = models.Relationship(User, related_name='entries',
rel_type='authored_by', single=True)
pub_date = models.DateTimeProperty(auto_now=True)
title = models.StringProperty(indexed=True)
slug = models.StringProperty()
body = models.StringProperty()
 
def __unicode__(self):
return self.title
 
def save(self, *args, **kwargs):
if not self.slug:
self.slug = slugify(self.title)[:50]
 
return super(Entry, self).save(*args, **kwargs)
urls.py
Python
1 2 3 4 5 6 7 8 9 10 11
from django.conf.urls import patterns, include
 
from myapp.api import EntryResource
 
entry_resource = EntryResource()
 
urlpatterns = patterns('',
# The normal jazz here...
#(r'^blog/', include('myapp.urls')),
(r'^api/', include(entry_resource.urls)),
)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.