PyCharm Global Search Shortcut: Ctrl + N
Xadmin Integration
/*
// Installation: pip install https://codeload.github.com/sshwsfc/xadmin/zip/django2
// ...\project_name\project_name\settings\development.py
INSTALLED_APPS = [
...,
'xadmin', // Main xadmin module
'crispy_forms', // Form rendering module
'reversion', // Version control module
];
// ...\project_name\project_name\urls.py
import xadmin
from xadmin.plugins import xversion
xadmin.autodiscover()
xversion.register_models()
urlpatterns = [
...,
path(r'xadmin/', xadmin.site.urls),
];
// Database migration: python manage.py migrate
// ...\project_name\project_name\apps\content\adminx.py
from . import models
xadmin.site.register(models.Slider)
*/
Frontend Slider Component
/*
// ...\frontend_app\src\components\Slider.vue
<template>
<!-- component template -->
</template>
<script>
export default {
name: "Slider",
data() {
return {
slider_items: [],
}
},
mounted() {
this.$http({
url: this.$configurations.api_base + '/content/sliders/',
method: 'GET',
params: {},
data: {},
}).then(response => {
this.slider_items = response.data
}).catch(error => {
console.error(error.response.data)
});
}
}
</script>
// ...\frontend_app\src\assets\js\configurations.js
export default {
api_base: 'http://localhost:8000',
}
// ...\frontend_app\src\main.js
import configurations from '@/assets/js/configurations'
Vue.prototype.$configurations = configurations;
*/
Backend Control of Slider Display Count
/*
// ...\project_name\project_name\settings\constants.py
SLIDER_LIMIT = 5
// ...\project_name\project_name\settings\development.py
from .constants import *
// ...\project_name\project_name\apps\content\views.py
from . import models, serializers
from rest_framework.generics import ListAPIView
from django.conf import settings
class SliderListAPIView(ListAPIView):
queryset = models.Slider.objects.filter(is_deleted=False, visible=True).order_by('-priority')[: settings.SLIDER_LIMIT]
serializer_class = serializers.SliderModelSerializer
*/
Git - Distributed Version Control System
Advantages: Git clients can temporarily serve as servers, and Git servers can be deployed in clusters.
Three Git Areas
Working directory, staging area, repository
Basic Commands
/*
1. View command help: git command -h
2. Clear terminal: clear
3. Initialize repository: git init /path/to/repo
4. Set global username and email: git config --global user.name 'username', git config --global user.email 'email'
5. Set local repo username and email: git config user.name 'username', git config user.email 'email'
6. Undo working directory changes: git checkout .
7. Move from staging back to working: git reset HEAD .
8. View detailed logs: git log, view brief logs: git reflog
9. Revert to specific commit: git reset --hard commit_hash
*/
Setting Up Ignore Files
- Files or folders matching patterns in ignore files will be filtered out by Git
/path/to/project/\_\_pycache\_\_/- Cache folder generated by imports/path/to/logs/app.logneeds filtering, but/path/to/logsdoes not
/*
// /path/to/repository/.gitignore
# Empty folders are ignored by default
temp_file.txt
/file_at_root.txt
*pattern*
*/
Branch Management Commands
/*
git branch feature_branch // Create feature_branch from current branch, remains on current branch
git branch // View local branches
git branch --all // View local and remote branches
git checkout feature_branch // Switch from current to feature_branch
git branch -d feature_branch // Delete feature_branch
git merge feature_dev // Merge feature_dev into current branch
*/
Remote Repository Management
/*
git remote add origin_repo git@host.com:user/repo.git // Link local to remote via SSH, origin_repo as alias
git remote --verbose // View all remote link details
git pull origin_repo dev // Sync remote dev to local dev
git push origin_repo main // Push local main to remote main
git remote remove origin_repo // Remove link
1. Generate key pair: ssh-keygen -t rsa -C "identifier"
2. View public key: cat ~/.ssh/id_rsa.pub
3. Add public key to account
git clone git@host.com:user/repo.git // Clone remote to local
Force remote rollback: 1. git pull origin_repo dev 2. git reset --hard hash 3. git push -f origin_repo dev
*/
Code Conflicts
Version and file conflicts are automatically resolved by Git.
Manual conflict resolution: Open conflicted files, integrate conflicting code, then re-pull, finally push.
Always pull before each push until no conflicts remain, then push.
Merging Online Repository Branches via Gitee
Select Pull Request to perform operations
- Regular branches: Branches where project members (developer-level permissions and above) can push
- Protected branches: Branches where only project administrators can push
- Read-only branches: Branches where no one (including administrators) can push