User Tools

Site Tools


code:django

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

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
 </code> </code>
 +
 +
 +===== Remove app from project =====
 +Source: http://techstream.org/Bits/Remove-App-From-Django-Project
 +
 +  * 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
 +</code>
 +
 +
 +===== ORM =====
 +
 +==== Subqueries ====
 +
 +=== Count ===
 +
 +<code python>
 +# database optimization
 +subquery = Subquery(
 +    Job.objects.published().filter(school=OuterRef('pk'))
 +        .values('school').annotate(count=Count('pk'))
 +        .values('count'), output_field=IntegerField()
 +    )
 +    qs = qs.annotate(jobs_count=Coalesce(subquery, 0))
 +</code>
 +
 +
 +
 +
code/django.1489164406.txt.gz ยท Last modified: 2017/03/10 17:46 by hansek