Moar work
This commit is contained in:
parent
343e8b8834
commit
f267d9d2e7
5 changed files with 21 additions and 3 deletions
3
flangr/posts/forms.py
Normal file
3
flangr/posts/forms.py
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
from django.forms import ModelForm
|
||||
|
||||
from .models import Comment
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -4,4 +4,5 @@ from . import views
|
|||
|
||||
urlpatterns = [
|
||||
path("post/<int:pk>", views.PostDetailView.as_view()),
|
||||
path("post/<int:pk>/comments", views.AddCommentView.as_view()),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -11,4 +11,10 @@
|
|||
<li>{{ comment.user }} - {{ comment.comment }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
<form action="{% url 'posts:add_comment' object.pk%}"
|
||||
method="post">
|
||||
{% csrf_token %}
|
||||
{{ add_comment_form }}
|
||||
<input type="submit", value="Post">
|
||||
</form>
|
||||
</body>
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue