Django is a free and open-source web framework, written in Python, which follows the model-view-template architectural pattern.
- Meta inner class in Django models
- select_related() vs prefetch_related(), Another Link
- Managing Concurrency in Django models
https://docs.djangoproject.com/en/2.0/misc/design-philosophies/#dry
- django-admin startproject project-name
- python manage.py runserver [ip : port]
- python manage.py startapp app-name
- python manage.py migrate
- python manage.py makemigrations app-name
- python manage.py sqlmigrate app-name migration-number
- python manage.py check
- python manage.py shell
- python manage.py createsuperuser
- python manage.py test app-name
python manage.py shell
- from polls.models import Choice, Question
- Question.objects.all()
- q = Question(question_text="What's new?", pub_date=timezone.now())
- q.save()
- Question.objects.filter(id=1)
- Question.objects.filter(question_text__startswith='What')
- q = Question.objects.get(pk=1)
- q.was_published_recently()
- q.choice_set.all()
- q.choice_set.create(choice_text='Not much', votes=0)
- c = q.choice_set.create(choice_text='Just hacking again', votes=0)
- c.question
- q.choice_set.count()
- c = q.choice_set.filter(choice_text__startswith='Just hacking')
- c.delete()
https://docs.djangoproject.com/en/2.0/intro/tutorial05/
>>> from django.test.utils import setup_test_environment
>>> setup_test_environment()
>>> from django.test import Client
>>> client = Client()
>>> response = client.get('/')
Not Found: /
>>> # we should expect a 404 from that address; if you instead see an
>>> # "Invalid HTTP_HOST header" error and a 400 response, you probably
>>> # omitted the setup_test_environment() call described earlier.
>>> response.status_code
404
>>> # on the other hand we should expect to find something at '/polls/'
>>> # we'll use 'reverse()' rather than a hardcoded URL
>>> from django.urls import reverse
>>> response = client.get(reverse('polls:index'))
>>> response.status_code
200
>>> response.content
b'\n <ul>\n \n <li><a href="/polls/1/">What's up?</a></li>\n \n </ul>\n\n'
>>> response.context['latest_question_list']
<QuerySet [<Question: What's up?>]>