This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
code:django [2017/03/10 17:46] hansek created |
code:django [2020/01/09 10:00] (current) hansek |
||
---|---|---|---|
Line 17: | Line 17: | ||
./manage.py migrate | ./manage.py migrate | ||
</ | </ | ||
+ | |||
+ | |||
+ | ===== Remove app from project ===== | ||
+ | Source: http:// | ||
+ | |||
+ | * Remove all imports and usage of the app in the project. | ||
+ | * Remove all models in models.py of the app. Can bring in error if the models are called in other files of the app like admin.py or any other so remove the reference or just delete the files expect __init__.py and models.py. | ||
+ | * Create a new migration for the app, which removes all models. | ||
+ | * Perform Migration. | ||
+ | * **Production** : If this is to be done in production, perform tests, push the code to production and perform migration before you proceed to next step. | ||
+ | * Remove the app from INSTALLED_APPS in settings.py. | ||
+ | * Delete the directory. | ||
+ | |||
+ | |||
+ | ===== Nginx reload ===== | ||
+ | <code bash> | ||
+ | sudo nginx -s reload | ||
+ | </ | ||
+ | |||
+ | |||
+ | ===== ORM ===== | ||
+ | |||
+ | ==== Subqueries ==== | ||
+ | |||
+ | === Count === | ||
+ | |||
+ | <code python> | ||
+ | # database optimization | ||
+ | subquery = Subquery( | ||
+ | Job.objects.published().filter(school=OuterRef(' | ||
+ | .values(' | ||
+ | .values(' | ||
+ | ) | ||
+ | qs = qs.annotate(jobs_count=Coalesce(subquery, | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ |