Skip to content

Commit 36c2001

Browse files
committed
Merge branch 'master' into prompt-engineering
2 parents 6d5a108 + 18854c1 commit 36c2001

File tree

703 files changed

+27149
-601
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

703 files changed

+27149
-601
lines changed

.github/workflows/linters.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
fail-fast: false
1919
matrix:
2020
include:
21-
- {name: Linux311, python: '3.11.0-rc.1', os: ubuntu-latest}
21+
- {name: Linux311, python: '3.11.5', os: ubuntu-latest}
2222
steps:
2323
- name: Check out repository
2424
uses: actions/checkout@v2
@@ -33,9 +33,9 @@ jobs:
3333
uses: actions/cache@v3
3434
with:
3535
path: ./venv
36-
key: ${{ matrix.name }}-pip-${{ hashFiles('requirements.txt') }}
36+
key: ${{ matrix.name }}-v1-pip-${{ hashFiles('requirements.txt') }}
3737
restore-keys: |
38-
${{ matrix.name }}-pip-
38+
${{ matrix.name }}-v1-pip-
3939
4040
- name: Install dependencies
4141
if: steps.cache.outputs.cache-hit != 'true'
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Create Your Own Blog With Django
2+
3+
Follow the [step-by-step instructions](https://realpython.com/get-started-with-django-1/) on Real Python to build your own blog with Django.
4+
5+
## Setup
6+
7+
You can run the provided example project on your local machine by following the steps outlined below.
8+
9+
Create a new virtual environment:
10+
11+
```bash
12+
$ python3 -m venv venv
13+
```
14+
15+
Activate the virtual environment:
16+
17+
```bash
18+
$ source venv/bin/activate
19+
```
20+
21+
Install the dependencies for this project if you haven't installed them yet:
22+
23+
```bash
24+
(venv) $ python -m pip install -r requirements.txt
25+
```
26+
27+
Make and apply the migrations for the project to build your local database:
28+
29+
```bash
30+
(venv) $ python manage.py makemigrations
31+
(venv) $ python manage.py migrate
32+
```
33+
34+
Run the Django development server:
35+
36+
```bash
37+
(venv) $ python manage.py runserver
38+
```
39+
40+
Navigate to `http://localhost:8000/` to see your blog in action.
41+
42+
## Using the Django Admin site
43+
44+
To create new posts, you need to create a superuser:
45+
46+
```bash
47+
(venv) $ python manage.py createsuperuser
48+
Username (leave blank to use 'root'): admin
49+
Email address: [email protected]
50+
Password: RealPyth0n
51+
Password (again): RealPyth0n
52+
Superuser created successfully.
53+
```
54+
55+
When running the `createsuperuser` managemant command you're prompted to choose a username, provide an email address, and set a password. Use your own data for these fields and make sure to remember them.
56+
57+
Navigate to `http://localhost:8000/admin` and log in with the credentials you just used to create a superuser.

rp-portfolio/blog/__init__.py renamed to build-a-blog-from-scratch-django/django-blog/blog/__init__.py

File renamed without changes.

rp-portfolio/blog/admin.py renamed to build-a-blog-from-scratch-django/django-blog/blog/admin.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
from django.contrib import admin
2-
from blog.models import Post, Category
2+
from blog.models import Category, Comment, Post
3+
4+
5+
class CategoryAdmin(admin.ModelAdmin):
6+
pass
37

48

59
class PostAdmin(admin.ModelAdmin):
610
pass
711

812

9-
class CategoryAdmin(admin.ModelAdmin):
13+
class CommentAdmin(admin.ModelAdmin):
1014
pass
1115

1216

13-
admin.site.register(Post, PostAdmin)
1417
admin.site.register(Category, CategoryAdmin)
18+
admin.site.register(Post, PostAdmin)
19+
admin.site.register(Comment, CommentAdmin)

rp-portfolio/blog/apps.py renamed to build-a-blog-from-scratch-django/django-blog/blog/apps.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33

44
class BlogConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
56
name = "blog"

rp-portfolio/blog/forms.py renamed to build-a-blog-from-scratch-django/django-blog/blog/forms.py

File renamed without changes.

rp-portfolio/blog/migrations/0001_initial.py renamed to build-a-blog-from-scratch-django/django-blog/blog/migrations/0001_initial.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Generated by Django 2.1.4 on 2018-12-16 19:11
1+
# Generated by Django 4.2.4 on 2023-08-29 12:43
22

33
from django.db import migrations, models
44
import django.db.models.deletion
@@ -15,40 +15,29 @@ class Migration(migrations.Migration):
1515
migrations.CreateModel(
1616
name='Category',
1717
fields=[
18-
('id', models.AutoField(auto_created=True, primary_key=True,
19-
serialize=False, verbose_name='ID')),
20-
('name', models.CharField(max_length=20)),
18+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
19+
('name', models.CharField(max_length=30)),
2120
],
2221
),
2322
migrations.CreateModel(
24-
name='Comment',
23+
name='Post',
2524
fields=[
26-
('id', models.AutoField(auto_created=True, primary_key=True,
27-
serialize=False, verbose_name='ID')),
28-
('author', models.CharField(max_length=60)),
25+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
26+
('title', models.CharField(max_length=255)),
2927
('body', models.TextField()),
3028
('created_on', models.DateTimeField(auto_now_add=True)),
29+
('last_modified', models.DateTimeField(auto_now=True)),
30+
('categories', models.ManyToManyField(related_name='posts', to='blog.category')),
3131
],
3232
),
3333
migrations.CreateModel(
34-
name='Post',
34+
name='Comment',
3535
fields=[
36-
('id', models.AutoField(auto_created=True, primary_key=True,
37-
serialize=False, verbose_name='ID')),
38-
('title', models.CharField(max_length=255)),
36+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
37+
('author', models.CharField(max_length=60)),
3938
('body', models.TextField()),
4039
('created_on', models.DateTimeField(auto_now_add=True)),
41-
('last_modified', models.DateTimeField(auto_now=True)),
42-
('categories', models.ManyToManyField(related_name='posts',
43-
to='blog.Category')),
40+
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='blog.post')),
4441
],
4542
),
46-
migrations.AddField(
47-
model_name='comment',
48-
name='post',
49-
field=models.ForeignKey(
50-
on_delete=django.db.models.deletion.CASCADE,
51-
to='blog.Post'
52-
),
53-
),
5443
]

rp-portfolio/blog/migrations/__init__.py renamed to build-a-blog-from-scratch-django/django-blog/blog/migrations/__init__.py

File renamed without changes.

rp-portfolio/blog/models.py renamed to build-a-blog-from-scratch-django/django-blog/blog/models.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22

33

44
class Category(models.Model):
5-
name = models.CharField(max_length=20)
5+
name = models.CharField(max_length=30)
6+
7+
class Meta:
8+
verbose_name_plural = "categories"
9+
10+
def __str__(self):
11+
return self.name
612

713

814
class Post(models.Model):
@@ -12,9 +18,15 @@ class Post(models.Model):
1218
last_modified = models.DateTimeField(auto_now=True)
1319
categories = models.ManyToManyField("Category", related_name="posts")
1420

21+
def __str__(self):
22+
return self.title
23+
1524

1625
class Comment(models.Model):
1726
author = models.CharField(max_length=60)
1827
body = models.TextField()
1928
created_on = models.DateTimeField(auto_now_add=True)
2029
post = models.ForeignKey("Post", on_delete=models.CASCADE)
30+
31+
def __str__(self):
32+
return f"{self.author} on '{self.post}'"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{% extends "blog/index.html" %}
2+
3+
{% block page_title %}
4+
<h2>{{ category }}</h2>
5+
{% endblock page_title %}

0 commit comments

Comments
 (0)