Skip to content

Instantly share code, notes, and snippets.

@javiergomezve
Forked from bradtraversy/django_crash_course.MD
Created September 28, 2019 22:36
Show Gist options
  • Save javiergomezve/355988e2a989f50ca315d6b29168f62a to your computer and use it in GitHub Desktop.
Save javiergomezve/355988e2a989f50ca315d6b29168f62a to your computer and use it in GitHub Desktop.

Revisions

  1. @bradtraversy bradtraversy revised this gist Sep 4, 2019. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions django_crash_course.MD
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,6 @@ pipenv install django
    ```bash
    # Create project
    django-admin startproject pollster
    ```
    ```bash
    cd pollster
    ```
    ```bash
  2. @bradtraversy bradtraversy revised this gist Sep 4, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions django_crash_course.MD
    Original file line number Diff line number Diff line change
    @@ -1,24 +1,27 @@
    # Django Crash Course Commands

    ```bash
    # Install pipenv
    pip install pipenv
    ```
    ```bash
    # Create Venv
    pipenv shell
    ```
    ```bash
    # Install Django
    pipenv install django
    ```
    ```bash
    # Create project
    django-admin startproject pollster
    ```
    ```bash
    cd pollster
    ```
    ```bash
    # Run server on http: 127.0.0.1:8000 (ctrl+c to stop)
    python manage.py runserver
    # Runs on http://127.0.0.1:8000
    # ctrl+c to stop
    ```
    ```bash
    # Run initial migrations
  3. @bradtraversy bradtraversy created this gist Sep 4, 2019.
    68 changes: 68 additions & 0 deletions django_crash_course.MD
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    # Django Crash Course Commands

    ```bash
    pip install pipenv
    ```
    ```bash
    pipenv shell
    ```
    ```bash
    pipenv install django
    ```
    ```bash
    django-admin startproject pollster
    ```
    ```bash
    cd pollster
    ```
    ```bash
    python manage.py runserver
    # Runs on http://127.0.0.1:8000
    # ctrl+c to stop
    ```
    ```bash
    # Run initial migrations
    python manage.py migrate
    ```
    ```bash
    # Create polls app
    python manage.py startapp polls
    ```
    ```bash
    # Create polls migrations
    python manage.py makemigrations polls
    ```
    ```bash
    # Run migrations
    python manage.py migrate
    ```
    ```bash
    # Using the shell
    python manage.py shell

    >>> from polls.models import Question, Choice
    >>> from django.utils import timezone
    >>> Question.objects.all()
    >>> q = Question(question_text="What is your favorite Python Framework?", pub_date=timezone.now())
    >>> q.save()
    >>> q.id
    >>> q.question_text
    >>> Question.objects.all()
    >>> Question.objects.filter(id=1)
    >>> Question.objects.get(pk=1)
    >>> q = Question.objects.get(pk=1)
    >>> q.choice_set.all()
    >>> q.choice_set.create(choice_text='Django', votes=0)
    >>> q.choice_set.create(choice_text='Flask', votes=0)
    >>> q.choice_set.create(choice_text='Flask', votes=0)
    >>> q.choice_set.all()
    >>> quit()
    ```
    ```bash
    # Create admin user
    python manage.py createsuperuser
    ```
    ```bash
    # Create pages app
    python manage.py startapp pages
    ```