Skip to content

Instantly share code, notes, and snippets.

@mhluongo
Last active December 18, 2015 13:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhluongo/5789513 to your computer and use it in GitHub Desktop.
Save mhluongo/5789513 to your computer and use it in GitHub Desktop.
A quick example using neo4django with tastypie adapted from the tastypie tutorial (http://django-tastypie.readthedocs.org/en/latest/tutorial.html).
from tastypie.resources import ModelResource
from .models import Entry
class EntryResource(ModelResource):
class Meta:
queryset = Entry.objects.all()
resource_name = 'entry'
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)
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)),
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment