I currently have fully functional commenting form in my blog post view that I want to display in the ListView. Sort of like linkedin has under every list item, if have noticed, i think facebook has the same thing.
Is there a shortcut to achieve this?
Should I post my code? For your professional eyes to see?
Probably the best way to handle this is to not use a ListView. My first reaction would be to not use any of the Django-provided generic views for this.
If I were doing something like this, I’d actually build this around a formset. I would treat the blog post as “extra data” being displayed along with the comment form. (This is probably more practical or appropriate if you’re looking for a full page display - perhaps less useful if you’re looking at implementing an “infinite scroll”-type application like facebook or linked in.)
If I were looking at an “infinite scroll” application knowing what I know now, I’d probably build it around HTMX for managing the page.
Can you please explain what you mean by “extra data”? As I understand–I should pass the commenting form, and the rest of the data of the blog as extras? If so, how can accomplish this, or read about it?
I’m currently reading the Formsets section in the docs.
When you have a form that you wish to display on a page along with some other data, you can look at this two different ways - you can either think about this as a page of data with a form added in, or you can think about this as displaying a form, with some other data associated with it.
What my recommendation is that you look at this as building a form that just also happens to have some other data being rendered along with it.
So as a very brief example that I hope might give you some ideas, let’s say you’ve created your formset for the list of posts you want to allow for comments.
Your template may look something like:
{% for form in formset %}
{% include 'blogpost.html' with blog=form.id %}
{{ form }}
{% endform %}
(This is just for illustration purposes only - obviously there’s a lot more needed for this in the view.)