Last active
December 18, 2015 13:19
-
-
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from tastypie.resources import ModelResource | |
from .models import Entry | |
class EntryResource(ModelResource): | |
class Meta: | |
queryset = Entry.objects.all() | |
resource_name = 'entry' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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