-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from pydanny/add-django-test-project
Add django test project
- Loading branch information
Showing
26 changed files
with
612 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -163,3 +163,4 @@ cython_debug/ | |
.vscode/ | ||
.ruff_cache/ | ||
changelog.json | ||
.idea |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
__author__ = 'Daniel Roy Greenfeld' | ||
__email__ = '[email protected]' | ||
__author__ = "Daniel Roy Greenfeld" | ||
__email__ = "[email protected]" | ||
|
||
|
||
def main(): | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Book, Author, Address, Country | ||
|
||
# Register your models here. | ||
|
||
|
||
class BookAdmin(admin.ModelAdmin): | ||
prepopulated_fields = {"slug": ("title",)} | ||
list_filter = ( | ||
"title", | ||
"rating", | ||
) | ||
list_display = ( | ||
"title", | ||
"author", | ||
) | ||
|
||
|
||
admin.site.register(Book, BookAdmin) | ||
admin.site.register(Author) | ||
admin.site.register(Address) | ||
admin.site.register(Country) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class BookOutletConfig(AppConfig): | ||
default_auto_field = "django.db.models.BigAutoField" | ||
name = "book_outlet" |
29 changes: 29 additions & 0 deletions
29
tests/django_test_project/book_outlet/migrations/0001_initial.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 4.2.2 on 2023-06-14 11:14 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Book", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("title", models.CharField(max_length=50)), | ||
("rating", models.IntegerField()), | ||
], | ||
), | ||
] |
34 changes: 34 additions & 0 deletions
34
..._project/book_outlet/migrations/0002_book_author_book_is_bestselling_alter_book_rating.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# Generated by Django 4.2.2 on 2023-06-14 16:20 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("book_outlet", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="book", | ||
name="author", | ||
field=models.CharField(max_length=100, null=True), | ||
), | ||
migrations.AddField( | ||
model_name="book", | ||
name="is_bestselling", | ||
field=models.BooleanField(default=False), | ||
), | ||
migrations.AlterField( | ||
model_name="book", | ||
name="rating", | ||
field=models.IntegerField( | ||
validators=[ | ||
django.core.validators.MinValueValidator(1), | ||
django.core.validators.MaxValueValidator(5), | ||
] | ||
), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
tests/django_test_project/book_outlet/migrations/0003_book_slug.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 4.2.2 on 2023-06-28 10:50 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("book_outlet", "0002_book_author_book_is_bestselling_alter_book_rating"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="book", | ||
name="slug", | ||
field=models.SlugField(default=""), | ||
), | ||
] |
44 changes: 44 additions & 0 deletions
44
...ango_test_project/book_outlet/migrations/0004_author_alter_book_slug_alter_book_author.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Generated by Django 4.2.2 on 2023-07-05 11:09 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("book_outlet", "0003_book_slug"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Author", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("first_name", models.CharField(max_length=100)), | ||
("last_name", models.CharField(max_length=100)), | ||
], | ||
), | ||
migrations.AlterField( | ||
model_name="book", | ||
name="slug", | ||
field=models.SlugField(blank=True, default=""), | ||
), | ||
migrations.AlterField( | ||
model_name="book", | ||
name="author", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="book_outlet.author", | ||
), | ||
), | ||
] |
24 changes: 24 additions & 0 deletions
24
tests/django_test_project/book_outlet/migrations/0005_alter_book_author.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.2.2 on 2023-07-05 11:33 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("book_outlet", "0004_author_alter_book_slug_alter_book_author"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="book", | ||
name="author", | ||
field=models.ForeignKey( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="books", | ||
to="book_outlet.author", | ||
), | ||
), | ||
] |
40 changes: 40 additions & 0 deletions
40
tests/django_test_project/book_outlet/migrations/0006_address_author_address.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Generated by Django 4.2.2 on 2023-07-12 11:12 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("book_outlet", "0005_alter_book_author"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Address", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("street", models.CharField(max_length=80)), | ||
("postal_code", models.CharField(max_length=5)), | ||
("city", models.CharField(max_length=50)), | ||
], | ||
), | ||
migrations.AddField( | ||
model_name="author", | ||
name="address", | ||
field=models.OneToOneField( | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="book_outlet.address", | ||
), | ||
), | ||
] |
38 changes: 38 additions & 0 deletions
38
...django_test_project/book_outlet/migrations/0007_country_alter_address_options_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Generated by Django 4.2.2 on 2023-07-14 09:35 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("book_outlet", "0006_address_author_address"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Country", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("name", models.CharField(max_length=80)), | ||
("code", models.CharField(max_length=2)), | ||
], | ||
), | ||
migrations.AlterModelOptions( | ||
name="address", | ||
options={"verbose_name_plural": "Address Entries"}, | ||
), | ||
migrations.AddField( | ||
model_name="book", | ||
name="published_countries", | ||
field=models.ManyToManyField(to="book_outlet.country"), | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
from django.db import models | ||
from django.core.validators import MinValueValidator, MaxValueValidator | ||
from django.urls import reverse | ||
from django.utils.text import slugify | ||
|
||
|
||
class Country(models.Model): | ||
name = models.CharField(max_length=80) | ||
code = models.CharField(max_length=2) | ||
|
||
def __str__(self): | ||
return f"{self.name}, {self.code}" | ||
|
||
class Meta: | ||
verbose_name_plural = "Countries" | ||
|
||
|
||
class Address(models.Model): | ||
street = models.CharField(max_length=80) | ||
postal_code = models.CharField(max_length=5) | ||
city = models.CharField(max_length=50) | ||
|
||
def __str__(self): | ||
return f"{self.street}, {self.postal_code}, {self.city}" | ||
|
||
class Meta: | ||
verbose_name_plural = "Address Entries" | ||
|
||
|
||
class Author(models.Model): | ||
first_name = models.CharField(max_length=100) | ||
last_name = models.CharField(max_length=100) | ||
address = models.OneToOneField(Address, on_delete=models.CASCADE, null=True) | ||
|
||
def full_name(self): | ||
return f"{self.first_name} {self.last_name}" | ||
|
||
def __str__(self): | ||
return self.full_name() | ||
|
||
|
||
class Book(models.Model): | ||
title = models.CharField(max_length=50) | ||
rating = models.IntegerField( | ||
validators=[MinValueValidator(1), MaxValueValidator(5)] | ||
) | ||
author = models.ForeignKey( | ||
Author, on_delete=models.CASCADE, null=True, related_name="books" | ||
) | ||
is_bestselling = models.BooleanField(default=False) | ||
slug = models.SlugField(default="", blank=True, null=False, db_index=True) | ||
published_countries = models.ManyToManyField(Country) | ||
|
||
def get_absolute_url(self): | ||
return reverse("book-detail", args=[self.slug]) | ||
|
||
def save(self, *args, **kwargs): | ||
self.slug = slugify(self.title) | ||
super().save(*args, **kwargs) | ||
|
||
def __str__(self): | ||
return f"{self.title} ({self.rating})" |
11 changes: 11 additions & 0 deletions
11
tests/django_test_project/book_outlet/templates/book_outlet/base.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<title>{% block title %}{% endblock %}</title> | ||
</head> | ||
<body> | ||
{% block content %} | ||
{% endblock %} | ||
</body> | ||
</html> |
17 changes: 17 additions & 0 deletions
17
tests/django_test_project/book_outlet/templates/book_outlet/book_detail.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{% extends "book_outlet/base.html" %} | ||
|
||
{% block title %} | ||
{{ title }} | ||
{% endblock %} | ||
|
||
{% block content %} | ||
<h1>{{ title }}</h1> | ||
<h2>{{ author }}</h2> | ||
<p> The book has a rating of {{ rating }} | ||
{% if is_bestseller %} | ||
and is a bestseller. | ||
{% else %} | ||
but isn't a bestseller. | ||
{% endif %} | ||
</p> | ||
{% endblock %} |
16 changes: 16 additions & 0 deletions
16
tests/django_test_project/book_outlet/templates/book_outlet/index.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends "book_outlet/base.html" %} | ||
|
||
{% block title %} All books {% endblock %} | ||
|
||
{% block content %} | ||
<ul> | ||
{% for book in books %} | ||
<li><a href="{{ book.get_absolute_url }}">{{book.title}} (Rating: {{ book.rating }})</a></li> | ||
{% endfor %} | ||
</ul> | ||
<hr> | ||
<p>Total Nuber of Books: {{ total_number_of_books }}</p> | ||
<p>Average Rating: {{ average_rating.rating__avg }}</p> | ||
|
||
{% endblock %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Create your tests here. |
Oops, something went wrong.