

Permission_classes = Ĭlass GroupViewSet(viewsets.ModelViewSet):ĪPI endpoint that allows groups to be viewed or edited. from import User, Groupįrom import UserSerializer, GroupSerializerĬlass UserViewSet(viewsets.ModelViewSet):ĪPI endpoint that allows users to be viewed or edited. Open tutorial/quickstart/views.py and get typing. Right, we'd better write some views then. You can also use primary key and various other relationships, but hyperlinking is good RESTful design. Notice that we're using hyperlinked relations in this case with HyperlinkedModelSerializer. from import User, GroupĬlass UserSerializer(serializers.HyperlinkedModelSerializer):įields = Ĭlass GroupSerializer(serializers.HyperlinkedModelSerializer):

Let's create a new module named tutorial/quickstart/serializers.py that we'll use for our data representations. Serializersįirst up we're going to define some serializers.

Once you've set up a database and the initial user is created and ready to go, open up the app's directory and we'll get coding. python manage.py createsuperuser -email -username admin We'll authenticate as that user later in our example. We'll also create an initial user named admin with a password of password123. Now sync your database for the first time: python manage.py migrate Using the project's namespace avoids name clashes with external modules (a topic that goes outside the scope of the quickstart). It may look unusual that the application has been created within the project directory. tutorial/quickstart/migrations/_init_.py The project layout should look like: $ pwd # Set up a new project with a single applicationĭjango-admin startproject tutorial. # Install Django and Django REST framework into the virtual environment Source env/bin/activate # On Windows use `env\Scripts\activate`

# Create a virtual environment to isolate our package dependencies locally Project setupĬreate a new Django project named tutorial, then start a new app called quickstart. We're going to create a simple API to allow admin users to view and edit the users and groups in the system.
