/Django-Web-Page

Django virtualenv python3

Primary LanguagePython

virtualenv ENV
cd ENV
source bin/activate
pip install django
python -m django --version
django-admin startproject mysite
cd mysite
python manage.py runserver
python manage.py startapp polls


set timezone
python manage.py migrate
add installed app
python manage.py makemigrations polls
(ENV) dylan@Malvin ~/temp/temp/temp/Django-Web-Page/ENV/mysite $ python manage.py makemigrations polls
Migrations for 'polls':
polls/migrations/0001_initial.py:
- Create model Choice
- Create model Question
- Add field question to choice
(ENV) dylan@Malvin ~/temp/temp/temp/Django-Web-Page/ENV/mysite $

python manage.py migrate

from polls.models import Question, Choice
Question.objects.all()
from django.utils import timezone
q = Question(question_text="What's new?", pub_date=timezone.now())
q.save()
q.id
q.question_text
q.pub_date
q.question_text = "What's up?"
q.save()
Question.objects.all()

def str(self):
It’s important to add str() methods to your models,
for your own convenience when dealing with the interactive prompt
and because objects’ representations are used throughout Django’s automatically-generated admin.

Question.objects.filter(id=1) Question.objects.filter(question_text__startswith='What') from django.utils import timezone current_year = timezone.now().year Question.objects.get(pub_date__year=current_year) Question.objects.get(id=2) Question.objects.get(id=2) # primary key q = Question.objects.get(pk=1) q.was_published_recently() q = Question.objects.get(pk=1) q.choice_set.all() q.choice_set.create(choice_text='Not much', votes=0) q.choice_set.create(choice_text='The sky', votes=0) c = q.choice_set.create(choice_text='Just hacking again', votes=0) c.question q.choice_set.all() q.choice_set.count() Choice.objects.filter(question__pub_date__year=current_year) c = q.choice_set.filter(choice_text__startswith='Just hacking') c.delete()

python manage.py createsuperuser