Django skills
Tag: Ruby
Tag: Rails
Category: jekyll
Category: update
Category: git
Category: database
Category: PostgreSQL
Category: websocket
Category: ruby
Category: projects
Category: Redis
Category: mysql
Category: Mac
Category: Node
Category: NPM
Category: PM2
Category: nodejs
Category: Meteor
Category: Nginx
Category: gitLab
Category: Rails
- Why Ruby on Rails is better than Python Django?
- How to use Hotwire turbo in Rails 6 with Webpacker?
- Rails 6 Credentials (master.key and credentials.yml.enc)
- Rails Console
- JIRA-Atlassian-Connect-App-Django
- Rails 4 5.0 Session Cookie AuthenticityToken
- Rails Active Storage
- Rails 5 Source code Research
- 微信支付
- Rails零星笔记
Category: Homebrew
Category: CentOS
Category: FreeSwitch
Category: Ruby
- Ruby on Rails 8
- RESTful API
- Ruby on Rails 7
- Study from Ruby official website
- Ruby-Metaprogramming
- Ruby连数据库的问题
- rbenv使用
Category: Vim
Category: javascript
Category: React-Native
Category: Wechat
Category: homeland
Category: JavaScript
Category: Docker
Category: RubyMine
Category: Authorization
Category: RESTful-API
Category: Proxy
Category: Deploy
Category: Devise
Category: Bootstrap
Category: Active_Storage
Category: github
Category: Android
Category: cloud
Category: ssh
Category: python
Category: reactjs
Category: markdown
Category: ShadowSocks
Category: Code
Category: rails
Category: code
Category: Django
Category: Python
Category: DRF
Category: Fish
Category: Yarn
Category: Material-UI
Category: CSS
Category: aws
Category: uwsgi
Category: nginx
Category: docker
Category: React
Category: Enzyme
Category: Jira
Category: Interview
Category: JetBrain
Category: PyCharm
Category: ESLint
Category: Rails6
Category: NVM
Category: ssl
Category: tencent
Category: CI
Category: jenkins
Category: GitHub
Category: Credentials
Category: master.key
Category: Webpacker
Category: Turbo
Category: Hotwire
Category: Bootstrap5
Category: Flutter
Category: Clash
Category: Tor
Category: proxy
Category: Build
Category: SwitchyOmega
Category: Chrome-extension
Category: SQLAlchemy
Category: Algorithm
Category: Rails7
Category: Data
Category: Structure
Category: CPP
Category: Languages
Category: Golang
Category: Typescript
Category: Rails 8
Migration
python manage.py migrate --fake yourproject 0041 # Mark the migration as it is there.
style = models.CharField(default='classic')
Django’s default for a Field is not set into Database column. It will be set by Django’s code.
So when we see this in migration script:
migrations.AddField(
model_name='project',
name='style',
field=models.CharField(default='classic', max_length=20),
preserve_default=False,
),
The preserve_default
is False
, so it is one-off code (more info: Django migration-operations).
Many to Many
- A ManyToMany field, now you want to make it through a model, how to make it? https://stackoverflow.com/questions/26927705/django-migration-error-you-cannot-alter-to-or-from-m2m-fields-or-add-or-remove
https://adriennedomingus.com/blog/django-adding-an-intermediate-model-to-a-manytomany-field-without-one
DB optimization
https://docs.djangoproject.com/en/3.1/topics/db/optimization/
https://docs.djangoproject.com/en/3.1/faq/models/#faq-see-raw-sql-queries
Kill n + 1 query
https://docs.djangoproject.com/en/3.0/ref/models/querysets/#prefetch-related
https://docs.djangoproject.com/en/3.0/ref/models/querysets/#django.db.models.prefetch_related_objects
https://docs.djangoproject.com/en/3.0/ref/models/querysets/#prefetch-objects
https://docs.djangoproject.com/en/3.0/ref/models/querysets/#django.db.models.query.QuerySet.defer
#####
from itertools import chain
queryset = queryset.filter(
github_account_id__in=chain(self.get_committer_ids(), self.get_reviewer_ids())
)
Here chain
need the value of self.get_committer_ids()
and self.get_reviewer_ids()
.
That means database query will be invoked immediately after self.get_committer_ids()
and self.get_reviewer_ids()
.
Invoked 2 times.
union
can help us avoid this problem.