Synopsis
This module is an add-on for Django REST Framework that serves a django model respecting the Linked Data Platform convention.
It aims at enabling people with little development skills to serve their own data, to be used with a LDP application.
Building a Startin' Blox application? Read this: https://git.happy-dev.fr/startinblox/devops/doc
Requirements
- Django (known to work with django 1.11)
- Django Rest Framework
- pyld==1.0.5
- django-guardian
- djangorestframework-guardian
Installation
- Install this module and all its dependencies
$ pip install djangoldp
- Create a django project
$ django-admin startproject myldpserver
- Add DjangoLDP to INSTALLED_APPS
INSTALLED_APPS = [
...
# make sure all of your own apps are installed BEFORE DjangoLDP
'djangoldp.apps.DjangoldpConfig',
]
IMPORTANT: DjangoLDP will register any models which haven't been registered, with the admin. As such it is important to add your own apps above DjangoLDP, so that you can use custom Admin classes if you wish
User model requirements
When implementing authentication in your own application, you have two options:
- Using or extending DjangoLDP-Account, a DjangoLDP package modelling federated users
- Using your own user model & defining the authentication behaviour yourself
Please see the Authentication guide for full information
If you're going to use your own model then for federated login to work your user model must extend DjangoLDP.Model
, or define a urlid
field on the user model, for example:
urlid = LDPUrlField(blank=True, null=True, unique=True)
If you don't include this field, then all users will be treated as users local to your instance
The urlid
field is used to uniquely identify the user and is part of the Linked Data Protocol standard. For local users it can be generated at runtime, but for some resources which are from distant servers this is required to be stored
Creating your first model
- Create your django model inside a file myldpserver/myldpserver/models.py Note that container_path will be use to resolve instance iri and container iri In the future it could also be used to auto configure django router (e.g. urls.py)
from djangoldp.models import Model
class Todo(Model):
name = models.CharField(max_length=255)
deadline = models.DateTimeField()
1.1. Configure container path (optional) By default it will be "todos/" with an S for model called Todo
<Model>._meta.container_path = "/my-path/"
1.2. Configure field visibility (optional) Note that at this stage you can limit access to certain fields of models using
<Model>._meta.serializer_fields (<>list of field names to show>)
For example, if you have a model with a related field with type django.contrib.auth.models.User you don't want to show personal details or password hashes.