forked from yahyaaly151989/Mastering_Django
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eb6a0fe
commit 921fbb0
Showing
16 changed files
with
115 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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
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,7 +1,13 @@ | ||
from django import forms | ||
from .models import Comment | ||
|
||
class EmailPostForm(forms.Form): | ||
name = forms.CharField(max_length=25) | ||
email = forms.EmailField() | ||
to = forms.EmailField() | ||
comments = forms.CharField(required=False, widget=forms.Textarea) | ||
|
||
class CommentForm(forms.ModelForm): | ||
class Meta: | ||
model = Comment | ||
fields = ['name', 'email', 'body'] |
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,31 @@ | ||
# Generated by Django 4.2.4 on 2023-08-20 12:32 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('blog', '0002_alter_post_slug'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Comment', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('name', models.CharField(max_length=80)), | ||
('email', models.EmailField(max_length=254)), | ||
('body', models.TextField()), | ||
('created', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
('active', models.BooleanField(default=True)), | ||
('post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='comments', to='blog.post')), | ||
], | ||
options={ | ||
'ordering': ['created'], | ||
'indexes': [models.Index(fields=['created'], name='blog_commen_created_0e6ed4_idx')], | ||
}, | ||
), | ||
] |
Binary file added
BIN
+1.8 KB
Module02/mysite/blog/migrations/__pycache__/0003_comment.cpython-311.pyc
Binary file not shown.
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
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,10 @@ | ||
{% extends "blog/base.html" %} | ||
{% block title %}Add a comment{% endblock %} | ||
{% block content %} | ||
{% if comment %} | ||
<h2>Your comment has been added.</h2> | ||
<p><a href="{{ post.get_absolute_url }}">Back to the post</a></p> | ||
{% else %} | ||
{% include "blog/post/includes/comment_form.html" %} | ||
{% endif %} | ||
{% 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
6 changes: 6 additions & 0 deletions
6
Module02/mysite/blog/templates/blog/post/includes/comment_form.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,6 @@ | ||
<h2>Add a new comment</h2> | ||
<form action="{% url "blog:post_comment" post.id %}" method="post"> | ||
{{ form.as_p }} | ||
{% csrf_token %} | ||
<p><input type="submit" value="Add comment"></p> | ||
</form> |
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
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
Binary file not shown.