github
https://github.com/manas-anarov/django_3_ninja/tree/4_part
blog/views.py
from .serializers import (
ListSerializer,
AddSerializer,
ShowSerializer,
)
from rest_framework.generics import (
ListAPIView,
CreateAPIView,
RetrieveAPIView,
)
from blog.models import Post
class ShowPost(RetrieveAPIView):
queryset = Post.objects.all()
serializer_class = ShowSerializer
lookup_field = 'id'
blog/serializers.py
class ShowSerializer(ModelSerializer):
class Meta:
model = Post
fields = [
'id',
'title',
'text',
]
blog/urls.py
urlpatterns = [
path('list/', views.PostListAPIView.as_view(), name='blog-list'),
path('add/', views.AddPost.as_view(), name='blog-add'),
path('<id>/', views.ShowPost.as_view(), name='blog-show'),
]
open link
http://localhost:8000/api/v1/post/list
show one post
http://localhost:8000/api/v1/post/1
пятница, 25 декабря 2020 г.
Django rest first application, Show Post RetrieveAPIView. Part 4
Upload files to django rest framework using react native
Uploading file using api in django rest framework. PythonAnywhere
https://youtu.be/BLN3EPjxQ_E
App.js
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
Button,
} from 'react-native';
export default class MyApp extends Component {
upload_image_to_django (){
PicturePath = "file:///storage/emulated/0/Download/myfoto.jpg";
URLpath = "http://manas93.pythonanywhere.com/file/upload/";
var formData = new FormData();
formData.append("file", {uri: PicturePath, name: 'myfoto.jpg', type: 'image/jpg'});
formData.append("remark", "Hello");
fetch( URLpath, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'multipart/form-data',
},
body: formData
})
.then((responseJson) => {
console.log(responseJson);
})
.catch(error => {
console.log(error);
})
}
render() {
return (
<View style={styles.content}>
<Button
title="My Button"
onPress={this.upload_image_to_django}
/>
</View>
);
}
}
var styles = StyleSheet.create({
content:{
flex:1,
flexDirection:'row',
alignItems:'center',
justifyContent:'center'
}
});
Django rest first application, Create Post CreateAPIView. Part 3
github
https://github.com/manas-anarov/django_3_ninja/tree/3_part
blog/views.py
from .serializers import (
ListSerializer,
AddSerializer,
)
from rest_framework.generics import (
ListAPIView,
CreateAPIView,
)
from blog.models import Post
class AddPost(CreateAPIView):
serializer_class = AddSerializer
queryset = Post.objects.all()
blog/serializers.py
lass AddSerializer(ModelSerializer):
class Meta:
model = Post
fields = [
'title',
'text',
]
blog/urls.py
urlpatterns = [
path('list/', views.PostListAPIView.as_view(), name='blog-list'),
path('add/', views.AddPost.as_view(), name='blog-add'),
]
open link
http://localhost:8000/api/v1/post/list
create post
http://localhost:8000/api/v1/post/add
понедельник, 21 декабря 2020 г.
Django rest first application, Show All Posts ListApiView. Part 2
open project folder
cd django_3_ninja
activate
pipenv shell
open folder
cd ninja_django
create app
python manage.py startapp blog
settings.py
INSTALLED_APPS = [
'blog',
]
blog/models.py
from django.db import models
class Post(models.Model):
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
title = models.CharField(max_length=200)
text = models.CharField(max_length=500)
def __str__(self):
return self.title
blog/views.py
from .serializers import (
ListSerializer,
)
from rest_framework.generics import (
ListAPIView,
)
from blog.models import Post
class PostListAPIView(ListAPIView):
serializer_class = ListSerializer
queryset = Post.objects.all()
blog/serializers.py
from rest_framework.serializers import (
ModelSerializer,
)
from blog.models import Post
class ListSerializer(ModelSerializer):
class Meta:
model = Post
fields = [
'id',
'title',
'text',
]
ninja_django/urls.py
from django.contrib import admin
from django.urls import path
from django.conf.urls import include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/v1/post/', include(('blog.urls', 'blog'), namespace='blog')),
]
blog/urls.py
from blog import views
from django.urls import path
urlpatterns = [
path('list/', views.PostListAPIView.as_view(), name='blog-list'),
]
install djangorestframework
pipenv install djangorestframework
settings.py
INSTALLED_APPS = [
'rest_framework',
]
blog/admin.py
from django.contrib import admin
from blog.models import Post
admin.site.register(Post)
create db
python manage.py makemigrations;
python manage.py migrate;
start server
python manage.py runserver;
create admin user
python manage.py createsuperuser
create post
http://localhost:8000/admin
open link
http://localhost:8000/api/v1/post/list
github
https://github.com/manas-anarov/django_3_ninja/tree/2_part
вторник, 15 декабря 2020 г.
Django rest first application, install Django3. Part 1

install virtual envoirment
pip3 install pipenv
create folder
mkdir django_3_ninja;
cd django_3_ninja;
install env for project
pipenv install
activate
pipenv shell
install django
pipenv install django~=3.1.4
start django project
django-admin startproject ninja_django;
cd ninja_django;
start server
python manage.py runserver;
open next link
http://127.0.0.1:8000/
github
https://github.com/manas-anarov/django_3_ninja/tree/1_part
суббота, 12 декабря 2020 г.
Python Developers (Mid/Senior). Location: Wroclaw
We are looking for Python Developers (Mid/Senior).
Python Team Lead Location: Cyprus, Limassol (Remote/Relocate)

