diff --git a/flangr/posts/forms.py b/flangr/posts/forms.py new file mode 100644 index 0000000..726a1c4 --- /dev/null +++ b/flangr/posts/forms.py @@ -0,0 +1,3 @@ +from django.forms import ModelForm + +from .models import Comment diff --git a/flangr/posts/models.py b/flangr/posts/models.py index 5799270..fa22ba2 100644 --- a/flangr/posts/models.py +++ b/flangr/posts/models.py @@ -8,8 +8,8 @@ from django.conf import settings def get_img_location(instance, filename): - uid = uuid.uuid4() - return f"{uid[0:2]}/{uid[2:]}".replace("-", "") + uid = uuid.uuid4().hex + return f"{uid[0:2]}/{uid[2:]}" class Post(models.Model): diff --git a/flangr/posts/urls.py b/flangr/posts/urls.py index 604330b..6bd7575 100644 --- a/flangr/posts/urls.py +++ b/flangr/posts/urls.py @@ -4,4 +4,5 @@ from . import views urlpatterns = [ path("post/", views.PostDetailView.as_view()), + path("post//comments", views.AddCommentView.as_view()), ] diff --git a/flangr/posts/views.py b/flangr/posts/views.py index d90837f..5fa1d08 100644 --- a/flangr/posts/views.py +++ b/flangr/posts/views.py @@ -1,9 +1,17 @@ from django.views.generic import DetailView +from django.forms import modelform_factory # Create your views here. -from .models import Post +from .models import Post, Comment class PostDetailView(DetailView): model = Post + + def get_context_data(self, **kwargs): + context = { + "add_comment_form": modelform_factory(Comment, fields=("comment",)), + **kwargs, + } + return super().get_context_data(**context) diff --git a/flangr/templates/posts/post_detail.html b/flangr/templates/posts/post_detail.html index 0ad7cae..d44eb00 100644 --- a/flangr/templates/posts/post_detail.html +++ b/flangr/templates/posts/post_detail.html @@ -11,4 +11,10 @@
  • {{ comment.user }} - {{ comment.comment }}
  • {% endfor %} +
    + {% csrf_token %} + {{ add_comment_form }} + +