Skip to content

Instantly share code, notes, and snippets.

@yoandresaav
Last active December 6, 2023 22:47
Show Gist options
  • Save yoandresaav/01ce184a1e6e1de508d3c19324f558b9 to your computer and use it in GitHub Desktop.
Save yoandresaav/01ce184a1e6e1de508d3c19324f558b9 to your computer and use it in GitHub Desktop.

Django Curated List from Yoandre

Table of Contents

  1. Classy Class-Based Views
  2. Classy Rest-Class
  3. Interested Links
  4. Deploy
  5. Database
  6. Django Rest Framework Tricks
  7. Url to Path
  8. Tips
  9. Server

Classy Class-Based Views

https://ccbv.co.uk/

Classy Django REST Framework

https://www.cdrf.co/

Interested Links

Deploy

https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/

Run manage.py check --deploy Some of the checks described below can be automated using the check --deploy option. Be sure to run it against your production settings file as described in the option’s documentation.

Rest Tricks

https://django-rest-framework-tricks.readthedocs.io/en/latest/

Url to Path

image from: https://consideratecode.com/2018/05/02/django-2-0-url-to-path-cheatsheet/

Database

https://books.agiliq.com/projects/django-orm-cookbook/en/latest/index.html

Re-Generate Migration

To merge exist migration files into one file:

  • Remove django_migration records table (manually)
  • Remove all migration files
  • run python manage.py migrate --fake command
  • run python manage.py makemigrations command
  • run python manage.py migrate --fake-initial command
  • run python manage.py migrate contenttypes command
  • and finally, for chacking if everything is just fine, run python manage.py migrate command

Now, check django_migration table and make sure all new files added in this table

Delete cache in Django

En el shell de django

from django.core.cache import cache cache.clear()

Fix Errors

Error: ModuleNotFoundError: No module named 'django.db.migrations.migration' Solution: reinstall becouse copy of django is corrupted

python -m django --version

pip install --upgrade --force-reinstall Django==3.2.2

Delete migrations

find . -path "/migrations/.py" -not -name "init.py" -delete find . -path "/migrations/.pyc" -delete

Clean all data in DB

python manage.py flush

Destroy DB

python manage.py reset_db

Show migrations

python manage.py showmigrations

Change password

python manage.py changepassword user

Cuando se pierde la BD y se puede usar otra BD

1 - Nueva BD en la tabla django_migrations eliminar las rows menos las 2 de contentypes al inicio. 2 - Eliminar todos los ficheros migrations. 3 - correr manage.py makemigrations 4 - correr manage.py migrate --fake

Tips

Server Admin

  • Run/Stop Services $ sudo systemctl status/start/stop/restart gunicorn/nginx

  • Ver logs $ journalctl --unit=gunicorn | tail -n 50

  • Ver la configuracion de Nginx $ sudo nginx -T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment