def get_client_ip(request):
Monday, 7 August 2023
get client IP address from django request
Sunday, 15 January 2023
Django rest framework Project tutorials part 5 modelviewset
In this tutorial, we are going study more about modelviewset
modelviewset
common policies
queryset
serializer_class
authentication_classes
permission_classes
allowed_methods
rare policies
renderer_classes
parser_classes
throttle_classes
content_negotiation_class
metadata_class
versioning_class
common overriding function for modelviewset
POST
GET
PUT
PATCH
DELETE
custom functions from action
@action(methods=['post'],detail=False,authentication_classes=[JWTTblUserAuthentication])
def change_password(self,request):
detailed explanation:-
get_queryset
we can modify queryset from get_queryset overriding function
use case
1.full record for user_type =staff or admin
2.customer can only manipulate his records
we only need to give the records with current user id matches the table record if user is customer or we can give full record if the user_type is staff or admin
get_authenticators
use case
remove authetication if new record is creating else use autheticator from default
authentication_classes=[JWTTblUserAuthentication]
if we are using method post then we dont need autheticator else we need JWTTblUserAuthentication
authetication
POST means we are using
create
default method is POST
use cases
1.we can manipulate the data like changing different serializer
2. checking user
3. changing response output if user is not customer,
destroy
default method is DELETE
def destroy(self, request, *args, **kwargs):
use case
we remove permission if user is destroying some others records
list
default method is GET
use case do pagination number to 50 from default
change serilizer_class
filter queryset with record type is apple only
retrieve
default method is GET
use case
check current user is the owner of the record then show detail of that record change serizlizer to detailed one
get_permissions
use case
if we need to put permission like create update delete for staff , and all others can only view the records
then we can override function like
Jenkin pipeline for angular
pipeline {
agent any
tools {nodejs "Node-12.10.0"}
environment {
NODE_OPTIONS = '--max-old-space-size=8192' //can be used in whole pipeline
}
stages {
stage('echo') {
steps {
echo env.NODE_OPTIONS
}
}
stage('Git') {
steps {
git branch: 'brnachname', credentialsId: 'xxxxxxxx-ccc7-49e2-a690-xxxxxxxxxxx', url: "git@****************"
}
}
stage('install_npm') {
steps {
sh 'npm install firebase@4.8.0'
sh 'npm install'
}
}
stage('prod_build') {
steps {
sh 'npm run ng build --prod --aot --output-hashing=all'
}
}
stage('delete_projectname') {
steps {
sh 'sudo rm -rf /home/deploy/apps/projectname'
}
}
stage('deploy_code_projectname') {
steps {
sh 'sudo cp -r ./dist/apps /home/deploy/apps/projectname'
}
}
}
}