Skip to content

Understand URL patterns #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
node_modules
.tmp
npm-debug.log
wisdompets/db.sqlite3
__pycache__/
*.py[cod]
3 changes: 0 additions & 3 deletions NOTICE
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ All Rights Reserved.
Licensed under the LinkedIn Learning Exercise File License (the "License").
See LICENSE in the project root for license information.

ATTRIBUTIONS:
[PLEASE PROVIDE ATTRIBUTIONS OR DELETE THIS AND THE ABOVE LINE “ATTRIBUTIONS”]

Please note, this project may automatically load third party code from external
repositories (for example, NPM modules, Composer packages, or other dependencies).
If so, such third party code may be subject to other license terms than as set
Expand Down
12 changes: 12 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"

[packages]
django = "==3.0.3"

[dev-packages]

[requires]
python_version = "3.9"
52 changes: 52 additions & 0 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
# COURSENAME
This is the repository for the LinkedIn Learning course [COURSENAME]. The full course is available from [LinkedIn Learning](LICOURSEURL).
# Learning Django
This is the repository for the LinkedIn Learning course Learning Django. The full course is available from [LinkedIn Learning](https://www.linkedin.com/learning/learning-django-2).

[![COURSENAME](COURSEIMAGE)](LICOURSEURL)

[COURSEDESCRIPTION]
With Django, you can take web applications from concept to launch in a matter of hours. It's a free and open-source framework that's designed on top of Python and supports data-driven architecture. In this course, learn what you need to know to get up and running with Django. Instructor Caleb Smith walks through creating a brand-new Django project, defining a data model and fields, querying the database, and using the framework's built-in URL handlers, views, and templates to structure the rest of the back end. Plus, learn how to incorporate CSS and JavaScript to enhance the style and usability of your Django templates.

## Instructions
This repository has branches for each of the videos in the course. You can use the branch pop up menu in github to switch to a specific branch and take a look at the course at that stage, or you can add `/tree/BRANCH_NAME` to the URL to go to the branch you want to access.

## Branches
The branches are structured to correspond to the videos in the course. The naming convention is `CHAPTER#_MOVIE#`. As an example, the branch named `02_03` corresponds to the second chapter and the third video in that chapter.
Some branches will have a beginning and an end state. These are marked with the letters `b` for "beginning" and `e` for "end". The `b` branch contains the code as it is at the beginning of the movie. The `e` branch contains the code as it is at the end of the movie. The `master` branch holds the final state of the code when in the course.

## Installing
1. To use these exercise files, you must have the following installed:
- [list of requirements for course]
2. Clone this repository into your local machine using the terminal (Mac), CMD (Windows), or a GUI tool like SourceTree.
3. [Course-specific instructions]
45 changes: 45 additions & 0 deletions starter_template.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Home - Wisdom Pet Medicine</title>
<link rel="stylesheet" id="ample-style-css" href="http://wisdompets.com/wp-content/themes/ample/style.css?ver=4.8.3" type="text/css" media="all">
</head>
<body class="wide">
<div id="page" class="hfeed site">
<header>
<div class="header">
<div class="main-head-wrap inner-wrap clearfix">
<div id="header-logo-image">
<a href="/">
<img src="http://wisdompets.com/wp-content/uploads/2015/10/wisdom-pet-logo-single.png" alt="Wisdom Pet Medicine">
</a>
</div>
<div id="header-text" class="">
<h1 id="site-title">
<a href="/" title="Wisdom Pet Medicine" rel="home">Wisdom Pet Medicine</a>
</h1>
<p>We treat your pets like we treat our own.</p>
</div>
</div>
<img src="http://wisdompets.com/wp-content/uploads/2015/10/1500x400-header_114150655.jpg" alt="Wisdom Pet Medicine">
</div>
</header>
<div class="main-wrapper">
<div class="single-page clearfix">
<div class="inner-wrap">
<p>Wisdom Pet Medicine strives to blend the best in traditional and alternative medicine in the diagnosis and treatment of health conditions in companion animals, including dogs, cats, birds, reptiles, rodents, and fish. We apply the latest healthcare technology, along with the wisdom garnered in the centuries old tradition of veterinary medicine, to find the safest and most effective treatments and cures, while maintaining a caring relationship with our patients and their guardians.</p>
<hr>
<div>
<!-- Insert content here-->
</div>
</div>
</div>
</div>
<footer id="colophon">
<div class="inner-wrap">
Wisdom Pet Medicine is a fictitious brand created by Lynda.com, solely for the purpose of training. All products and people associated with Wisdom Pet Medicine are also fictitious. Any resemblance to real brands, products, or people is purely coincidental. Please see your veterinarian for all matters related to your pet's health.
</div>
</footer>
</div>
</body>
</html>
Empty file.
7 changes: 7 additions & 0 deletions wisdompets/adoptions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.contrib import admin

from .models import Pet

@admin.register(Pet)
class PetAdmin(admin.ModelAdmin):
list_display = ['name', 'species', 'breed', 'age', 'sex']
5 changes: 5 additions & 0 deletions wisdompets/adoptions/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class AdoptionsConfig(AppConfig):
name = 'adoptions'
Empty file.
62 changes: 62 additions & 0 deletions wisdompets/adoptions/management/commands/load_pet_data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
from csv import DictReader
from datetime import datetime

from django.core.management import BaseCommand

from adoptions.models import Pet, Vaccine
from pytz import UTC
# these are imported

DATETIME_FORMAT = '%m/%d/%Y %H:%M'

VACCINES_NAMES = [
'Canine Parvo',
'Canine Distemper',
'Canine Rabies',
'Canine Leptospira',
'Feline Herpes Virus 1',
'Feline Rabies',
'Feline Leukemia'
]

ALREDY_LOADED_ERROR_MESSAGE = """
If you need to reload the pet data from the CSV file,
first delete the db.sqlite3 file to destroy the database.
Then, run `python manage.py migrate` for a new empty
database with tables"""


class Command(BaseCommand):
# Show this when the user types help
help = "Loads data from pet_data.csv into our Pet mode"

def handle(self, *args, **options):
if Vaccine.objects.exists() or Pet.objects.exists():
print('Pet data already loaded...exiting.')
print(ALREDY_LOADED_ERROR_MESSAGE)
return
print("Creating vaccine data")
for vaccine_name in VACCINES_NAMES:
vac = Vaccine(name=vaccine_name)
vac.save()
print("Loading pet data for pets available for adoption")
for row in DictReader(open('./pet_data.csv')):
pet = Pet()
pet.name = row['Pet']
pet.submitter = row['Submitter']
pet.species = row['Species']
pet.breed = row['Breed']
pet.description = row['Pet Description']
pet.sex = row['Sex']
pet.age = row['Age']
raw_submission_date = row['submission date']
submission_date = UTC.localize(
datetime.strptime(raw_submission_date, DATETIME_FORMAT))
pet.submission_date = submission_date
pet.save()
raw_vaccination_names = row['vaccinations']
vaccination_names = [name for name in raw_vaccination_names.split('| ') if name]
for vac_name in vaccination_names:
vac = Vaccine.objects.get(name=vac_name)
pet.vaccinations.add(vac)
pet.save()
47 changes: 47 additions & 0 deletions wisdompets/adoptions/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Generated by Django 3.0.3 on 2020-12-23 02:33

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
]

operations = [
migrations.CreateModel(
name='Blank',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('blank', models.CharField(max_length=100)),
('breed', models.CharField(max_length=100)),
('administered_vaccines', models.CharField(max_length=100)),
('adoption_status', models.CharField(max_length=100)),
('other_details', models.CharField(max_length=100)),
],
),
migrations.CreateModel(
name='Vaccine',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=50)),
],
),
migrations.CreateModel(
name='Pet',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=100)),
('submitter', models.CharField(max_length=100)),
('species', models.CharField(max_length=30)),
('breed', models.CharField(blank=True, max_length=30)),
('description', models.TextField()),
('sex', models.CharField(blank=True, choices=[('M', 'Male'), ('F', 'Female')], max_length=1)),
('submission_date', models.DateTimeField()),
('age', models.IntegerField(null=True)),
('vaccinations', models.ManyToManyField(blank=True, to='adoptions.Vaccine')),
],
),
]
16 changes: 16 additions & 0 deletions wisdompets/adoptions/migrations/0002_delete_blank.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 3.0.3 on 2020-12-23 23:30

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('adoptions', '0001_initial'),
]

operations = [
migrations.DeleteModel(
name='Blank',
),
]
Empty file.
19 changes: 19 additions & 0 deletions wisdompets/adoptions/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from django.db import models

class Pet(models.Model):
SEX_CHOICES = [('M', 'Male'), ('F', 'Female')]
name = models.CharField(max_length=100)
submitter = models.CharField(max_length=100)
species = models.CharField(max_length=30)
breed = models.CharField(max_length=30, blank=True)
description = models.TextField()
sex = models.CharField(max_length=1, choices=SEX_CHOICES, blank=True)
submission_date = models.DateTimeField()
age = models.IntegerField(null=True)
vaccinations = models.ManyToManyField('Vaccine', blank=True)

class Vaccine(models.Model):
name = models.CharField(max_length=50)

def __str__(self):
return self.name
49 changes: 49 additions & 0 deletions wisdompets/adoptions/templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{% load static %}
<html lang="en-US">
<head>
<meta charset="UTF-8">
<title>Home - Wisdom Pet Medicine</title>
<link rel="stylesheet" id="ample-style-css" href="{% static 'style.css' %}" type="text/css" media="all">
</head>
<body class="wide">
<div id="page" class="hfeed site">
<header>
<div class="header">
<div class="main-head-wrap inner-wrap clearfix">
<div id="header-logo-image">
<a href="/">
<img src="{% static 'images/logo.png' %}" alt="Wisdom Pet Medicine">
</a>
</div>
<div id="header-text" class="">
<h1 id="site-title">
<a href="/" title="Wisdom Pet Medicine" rel="home">Wisdom Pet Medicine</a>
</h1>
<p>We treat your pets like we treat our own.</p>
</div>
</div>
<img src="{% static "images/header.jpg" %}" alt="Wisdom Pet Medicine">
</div>
</header>
<div class="main-wrapper">
<div class="single-page clearfix">
<div class="inner-wrap">
<p>Wisdom Pet Medicine strives to blend the best in traditional and alternative medicine in the diagnosis and treatment of health conditions in companion animals, including dogs, cats, birds, reptiles, rodents, and fish. We apply the latest healthcare technology, along with the wisdom garnered in the centuries old tradition of veterinary medicine, to find the safest and most effective treatments and cures, while maintaining a caring relationship with our patients and their guardians.</p>
<hr>
<div>
{% block content %}
{% endblock %}

</div>
</div>
</div>
</div>
<footer id="colophon">
<div class="inner-wrap">
Wisdom Pet Medicine is a fictitious brand created by Lynda.com, solely for the purpose of training. All products and people associated with Wisdom Pet Medicine are also fictitious. Any resemblance to real brands, products, or people is purely coincidental. Please see your veterinarian for all matters related to your pet's health.
</div>
</footer>
</div>
<script src={% static 'main.js' %}></script>
</body>
</html>
19 changes: 19 additions & 0 deletions wisdompets/adoptions/templates/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{% extends "base.html" %}
{% block content %}


<div>
{% for pet in pets %}
<div class="petname">
<a href="{% url 'pet_detail' pet.id %}">
<h3> {{ pet.name|capfirst }}</h3>
</a>
<p>{{ pet.species }}</p>
{% if pet.breed %}
<p>Breed: {{ pet.species }}</p>
{% endif %}
<p class="hidden"> {{ pet.description }} </p>
</div>
{% endfor %}
</div>
{% endblock content %}
Loading