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
| django_blog | |
| ├── api | |
| │ ├── django_blog | |
| │ │ ├── apps | |
| │ │ │ ├── account | |
| │ │ │ │ ├── admin.py | |
| │ │ │ │ ├── apps.py | |
| │ │ │ │ ├── forms.py | |
| │ │ │ │ ├── __init__.py | |
| │ │ │ │ ├── managers.py |
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.test import TestCase | |
| from django_blog.apps.blog.models import Post, Tag | |
| class PostTestCase(TestCase): | |
| def test_post(self): | |
| self.assertEquals( | |
| Post.objects.count(), | |
| 0 |
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.db import models | |
| from django_blog.apps.account.models import User | |
| from django_blog.apps.common.models import CoreModel | |
| class Tag(models.Model): | |
| name = models.CharField(max_length=100, unique=True) | |
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
| Creating test database for alias 'default'... | |
| System check identified no issues (0 silenced). | |
| .. | |
| ---------------------------------------------------------------------- | |
| Ran 2 tests in 0.005s | |
| OK |
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.urls import reverse | |
| from rest_framework.test import APITestCase | |
| from rest_framework.views import status | |
| from django_blog.apps.blog.models import Post, Tag | |
| class PostListCreateAPIView(APITestCase): | |
| def setUp(self) -> None: |
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 rest_framework import serializers | |
| from django_blog.apps.account.models import User | |
| from django_blog.apps.blog.models import Tag, Post | |
| class UserSerializer(serializers.ModelSerializer): | |
| class Meta: | |
| model = User | |
| fields = ('pk', 'email', 'first_name', 'last_name',) |
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_blog.apps.blog.models import Post | |
| from django_blog.apps.blog.rest_api.serializers.post import PostSerializer | |
| post = Post.objects.create(title='First post', text='This is a first post') | |
| print(PostSerializer(post).data) | |
| # {'pk': '4670511f-4a03-455e-a160-18c396fa743d', 'title': 'First post', 'text': 'This is a first post', 'tags': [], 'author': None, 'image': None} |
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 rest_framework.generics import ListCreateAPIView, RetrieveUpdateDestroyAPIView | |
| from django_blog.apps.blog.models import Post | |
| from django_blog.apps.blog.rest_api.serializers.post import PostSerializer | |
| class PostListCreateAPIView(ListCreateAPIView): | |
| """ | |
| API view to retrieve list of posts or create new | |
| """ |
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.urls import path | |
| from .views import blog_views | |
| urlpatterns = [ | |
| path('posts/', blog_views.PostListCreateAPIView.as_view(), name='api-post-list'), | |
| path('posts/<uuid:pk>/', blog_views.PostDetailsAPIView.as_view(), name='api-post-details'), | |
| ] |
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
| Creating test database for alias 'default'... | |
| System check identified no issues (0 silenced). | |
| ....... | |
| ---------------------------------------------------------------------- | |
| Ran 7 tests in 0.036s | |
| OK | |
| Destroying test database for alias 'default'... |
OlderNewer