mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-30 05:24:00 +03:00
Merge pull request #2219 from linovia/bugfix/tutorial_2
Update the tutorial against DRF v3 (part 4 & 5)
This commit is contained in:
commit
71c49fea8a
|
@ -43,7 +43,7 @@ And now we can add a `.save()` method to our model class:
|
||||||
When that's all done we'll need to update our database tables.
|
When that's all done we'll need to update our database tables.
|
||||||
Normally we'd create a database migration in order to do that, but for the purposes of this tutorial, let's just delete the database and start again.
|
Normally we'd create a database migration in order to do that, but for the purposes of this tutorial, let's just delete the database and start again.
|
||||||
|
|
||||||
rm tmp.db
|
rm -f tmp.db db.sqlite3
|
||||||
rm -r snippets/migrations
|
rm -r snippets/migrations
|
||||||
python manage.py makemigrations snippets
|
python manage.py makemigrations snippets
|
||||||
python manage.py migrate
|
python manage.py migrate
|
||||||
|
@ -59,7 +59,7 @@ Now that we've got some users to work with, we'd better add representations of t
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
|
|
||||||
class UserSerializer(serializers.ModelSerializer):
|
class UserSerializer(serializers.ModelSerializer):
|
||||||
snippets = serializers.PrimaryKeyRelatedField(many=True)
|
snippets = serializers.PrimaryKeyRelatedField(many=True, queryset=Snippet.objects.all())
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = User
|
model = User
|
||||||
|
|
|
@ -44,7 +44,7 @@ Instead of using a concrete generic view, we'll use the base class for represent
|
||||||
As usual we need to add the new views that we've created in to our URLconf.
|
As usual we need to add the new views that we've created in to our URLconf.
|
||||||
We'll add a url pattern for our new API root in `snippets/urls.py`:
|
We'll add a url pattern for our new API root in `snippets/urls.py`:
|
||||||
|
|
||||||
url(r'^$', 'api_root'),
|
url(r'^$', views.api_root),
|
||||||
|
|
||||||
And then add a url pattern for the snippet highlights:
|
And then add a url pattern for the snippet highlights:
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user