DJ-Stripe metadata not attaching to product - django

I am following this guide:
https://www.saaspegasus.com/guides/django-stripe-integrate/#contents
I get to "Adding metadata to your Stripe objects" and am told to create a metadata.py file. It doesn't tell me where to import #dataclass and List from so I had to guess. The issue is that, moving forward from this point in the guide, the metadata does not print to my template but I can retrieve product information. I'm thinking this guide is missing or assuming I know stuff about metadata that is required to make it work.
my metadata.py:
from dataclasses import dataclass
from pip import List
from project.subscriptions import features
#dataclass
class ProductMetadata(object):
"""
Metadata for a Stripe product.
"""
stripe_id: str
name: str
features: List[str]
description: str = ''
is_default: bool = False
PREMIUM = ProductMetadata(
stripe_id='<prod id>',
name='Premium',
description='yerp',
is_default=False,
features=[
features.UNLIMITED_WIDGETS,
features.LUDICROUS_MODE,
features.PRIORITY_SUPPORT,
],
)
features.py:
UNLIMITED_WIDGETS = 'Unlimited Widgets'
LUDICROUS_MODE = 'Ludicrous Mode'
PRIORITY_SUPPORT = 'Priority Support'
views:
from django.shortcuts import render
from djstripe.models import Product
def pricing_page(request):
context = {
'products': Product.objects.all()
}
return render(request,'subscriptions/pricing_page.html', context=context)
urls:
path('pricing_page/', view=pricing_page, name='pricing_page'),
template:
{% extends "base.html" %}{% load static socialaccount %}
{% block content %}
<h1>Plans</h1>
<section>
<p class="title">Pricing Plans</p>
<div class="columns">
{% for product in products %}
<div class="column">
<p class="subtitle">{{ product.name }}</p>
{% for plan in product.plan_set.all %}
<div>
<p class="heading">{{ plan.nickname }}</p>
<p>{{ plan.human_readable_price }}</p>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
</section>
<div class="plan-interval-selector">
{% for plan in plans %}
<button class="button">{{ plan.name }}</button>
{% endfor %}
</div>
<div class="columns plan-selector">
{% for product in products %}
{{ product.metadata|pprint }}
<div class="column">
<div {% if product.metadata.is_default %}class="is-selected"{% endif %}>
<span class="icon">
<i class="fa {% if product.metadata.is_default %}fa-check{% else %}fa-circle{% endif %}">
</i>
</span>
<p class="plan-name">{{ product.metadata.name }}</p>
<p class="plan-description">{{ product.metadata.description }}</p>
<div class="plan-price">
<span class="price">{{ product.metadata.monthly_price }}</span> / month
</div>
<ul class="features">
{% for feature in product.metadata.features %}
<li>
<span class="icon"><i class="fa fa-check"></i></span>
<span class="feature">{{ feature }}</span>
</li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
{% endblock content %}
The first forloop gets attributes directly from the product and it works. The second one tries to get the attributes from the metadata. It loops for each product but does not output the metadata. Any advice?

Related

How to customise task context (process_data cards) in django-viewflow

What I want
I'm building an approval workflow using django-viewflow and django-material.
The individual tasks are rendered as a main form with context on a very narrow column on the right-hand side.
I want to change the layout so that the task context (the detail views of all involved model instances) is better readable to the user, and also customise which fields are shown (eg. exclude a user's password hash).
Where I'm stuck
Is there a way to override which data is available as process_data short of overriding viewflow's get_model_display_data and include_process_data? E.g. I'd like to have the related instance's __str__() as title.
Does viewflow have any canonical way to provide individual detail card templates? My alternative would be to completely re-work the contents of the process_data sidebar using context['process'] as the central instance, but that would tie the templates to the data model.
Are django-material formsets with read-only fields and a custom layout the answer I'm after? (I will try this out as soon as I have a viewflow pro license.)
I'd be grateful on any pointers here.
What I've tried
I'm overriding/extending the viewflow templates. As per templatetag include_process_data, the template process_data.html supplies the column of model instance detail cards, fed by data from
get_model_display_data.
It's e.g. easy to override process_data.html to change the cards into a MaterializeCSS collapsible list:
{% load i18n viewflow material_frontend viewflow_frontend %}
<!--
This is template "APP_NAME/PROCESS_NAME/process_data.html" overriding "viewflow/flow/process_data.html".
We override instead of extending as "viewflow/flow/process_data.html" has no content block.super
Changes:
* Collapsible list of process context instead of cards.
-->
<script type="text/javascript">
$(document).ready(function () { $('.collapsible').collapsible(); });
</script>
<ul class="collapsible">
{% for root, fields, root_url in process_data %}
<li>
<div class="collapsible-header">
<span class="card-title">{{ root }} #{{ process.pk }}</span>
{% if root_url and request.user.is_staff %}
<a href="{{ root_url }}" class="card-edit" target="_blank" data-turbolinks="false" style="float:right">
{% trans 'edit' %}
</a>
{% endif %}
</div>
<div class="collapsible-body process_data_content">
<dl class="dl-horizontal">
{% for name, value in fields %}
<dt>{{ name }}:</dt>
<dd>
{% if value is True %}{% trans 'Yes' %}{% else %}
{% if value is False %}{% trans 'No' %}{% else %}
{% if value and value.url %}{{ value.name }}{% else %}
{{ value }}{% endif %}{% endif %}{% endif %}
</dd>
{% endfor %}
</dl>
</div>
{% if not hide_active_tasks and forloop.counter == 1 and process.active_tasks %}
<li>
<div class="collapsible-header">
<span class="card-title">{% trans 'Active tasks' %}</span>
</div>
<div class="collapsible-body process_data_content">
<table>
<thead>
<tr>
<th>{% trans 'Task' %}</th>
<th>{% trans 'Owner' %}</th>
</tr>
</thead>
<tbody>
{% for task in process.active_tasks %}
{% if task.flow_task.task_type == 'HUMAN' or task.flow_task.task_type == 'JOB' %}
<tr>
<td>
{{ task.flow_task}}/#{{ task.pk}}
</td>
<td>{{ task.owner|default:"" }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
</div>
</li>
{% endif %}
</li>
{% endfor %}
</ul>
Overriding the template viewflow/flow/task.html with my own APP_NAME/PROCESS_NAME/TASK_NAME.html template at the cost of including model-specific information can show e.g. customised cards of related instances over the main form. I would refactor the individual cards into their own templates.
{% extends "viewflow/flow/task.html" %}
{% block left-panel__top %}
<!--
This is template "APP_NAME/PROCESS_NAME/TASK_NAME.html" extending "viewflow/flow/task.html".
-->
<!-- Help specific to this step goes here. -->
{% with activation.process as p %}
<div class="row">
<h3>Nested formsets</h3>
<p>These cards are placeholders for formsets nested within the main application form.</p>
<p>Nested formsets and the main application form can be updated at the same time and have exactly one submission button.</p>
</div>
<div class="row">
<!-- Organisation Questions: Answers -->
<!-- TODO refactor to template include -->
{% for x in p.organisationanswer_set.all %}
<div class="col s12 m6 xl4">
<div class="card blue-grey darken-1">
<div class="card-content white-text">
<span class="card-title">
{{ x.question.question }}
</span>
<p><strong>Your answer:</strong> {{ oa.answer }}</p>
</div>
<div class="card-action">
Provide an answer
</div>
</div>
</div>
{% endfor %}
<!-- Dataset Questions: Answers -->
{% for x in p.datasetanswer_set.all %}
<div class="col s12 m6 xl4">
<div class="card blue-grey darken-1">
<div class="card-content white-text">
<span class="card-title">
{{ x.question.question }}
</span>
<p><strong>Your answer:</strong> {{ x.answer }}</p>
</div>
<div class="card-action">
Provide an answer
</div>
</div>
</div>
{% endfor %}
<!-- Approvals: Receipts - TODO show this in task after custodian approval -->
{% for x in p.approvalreceipt_set.all %}
<div class="col s12 m6 xl4">
<div class="card blue-grey darken-1">
<div class="card-content white-text">
<span class="card-title">
{{ x.approval }}
</span>
<p><strong>Your approval receipt:</strong> {{ x.receipt }}</p>
</div>
<div class="card-action">
Provide an answer
</div>
</div>
</div>
{% endfor %}
</div>
{% endwith %}
<div class="row">
<h3>Main application form</h3>
<p>These main application form would include the forms above as nested formsets.</p>
<p>This note will disappear once this has been implemented.</p>
</div>
{% endblock %}
For the basic cases create a template named as [app_label]/[flow_label]/process_data.html For example check the shipment demo
Viewflow is the thin workflow layer on top of the standard Django model-view-template pattern. Any customization practices for Django are valid for Viewflow
For the complex cases it's better to not to tune some universal implementation, but create your own set of templates for Viewflow, ex cookbook/custom_ui

How to display child element in Django MPTT?

I am trying to call parent and child element of a model, I have gone through the MPTT model documentation. I did as mentioned on the documentation, but my template is failing to print children
What can be the possible cause of this problem?
Here is my Views:
def category_view(request):
category = Categories.objects.all()
brands = Brands.objects.all()
context ={
'category':category,
'brands':brands,
}
return render(request,'./ecommerce/categories.html', context)
and Here is my template HTML:
{% load mptt_tags %}
{% recursetree category%}
<div class="category-wrap mb-4">
<div class="category category-group-image br-sm">
<div class="category-content">
<h4 class="category-name">{{ node.name }}
</h4>
<ul class="category-list">
{% if not node.is_leaf_node %}
<li>{{children}}</li>
{% endif %}
</ul>
</div>
</div>
</div>
<!-- End of Category Wrap -->
{% endrecursetree %}
Parent element is printed but children element is not being printed
Doing a lot of hit and trial, generic approach solved my problem. Others having similar problem could be benefited from my answer, hence posting the solution.
Views:
category = Categories.objects.filter(parent=None)
Template:
{% for category in categories %}
<div class="category-wrap mb-4">
<div class="category category-group-image br-sm">
<div class="category-content">
<h4 class="category-name">{{ category.name }}
</h4>
<ul class="category-list">
{% for cat in category.get_children %}
<li>{{ cat.name }} </li>
{% endfor %}
</ul>
</div>
</div>
</div>
<!-- End of Category Wrap -->
{% endfor %}

why when I click a different user returns me back to the current request user?

sorry, I had to take some screenshots to explains what is going on with me. now, I have much profile that has many different users and when I log in with one of it I'll assume the username is: medoabdin like you find on the screenshot now (medoabdin) and the name of it is (Origin) for me is a current user request. so, now I have also many different questions created by the different users, and when I want to enter any other profile let's suppose the user is (abdelhamedabdin) by current request user it returns me back to the current request (medoabdin) and not returns me back to abdelhamedabdin.
however, when I check the link URL I find the link is correct and when I log in with (abdelhamedabdin) user I see the same thing occurs to me against (medoabdin) so, can anyone tell me what is going on guys?
these are screenshots:
current request (medoabdin),
several questions,
show the link url for different users,
accounts/profile.html
{% extends 'base.html' %}
{% block title %} {{ user.first_name }} {{ user.last_name }} Profile {% endblock %}
{% block body %}
<!-- User Profile Section -->
{% if user.is_authenticated %}
<div class="profile">
<div class="container-fluid">
<div class="col-md-1">
<div class="thumbnail">
<div class="row">
<div class="col-xs-12">
<!-- Profile View Section -->
<div class="logo-image text-center">
{% if user.userprofile.logo %}
<div class="my-image">
{% if request.user.username == user.userprofile.slug %}
<a href="{% url 'accounts:user_image' user.userprofile.slug %}">
<img class="img-responsive" src="{{ user.userprofile.logo.url }}">
</a>
<span>
<a href="{% url 'accounts:add_avatar' user.userprofile.slug %}" class="fa fa-camera fa-1x text-center">
<p>Upload Image</p>
</a>
</span>
{% endif %}
</div>
{% else %}
{% load static %}
<div class="my-image">
<img class="img-responsive img-thumbnail" src="{% static 'index/images/default-logo.jpg' %}">
<span>
<a href="{% url 'accounts:add_avatar' user.userprofile.slug %}" class="fa fa-camera fa-1x text-center">
<p>Upload Image</p>
</a>
</span>
</div>
{% endif %}
{% if user.first_name != '' and user.last_name != '' %}
<h4>{{ user.first_name }} {{ user.last_name }}</h4>
{% else %}
<h4>User Profile</h4>
{% endif %}
</div>
</div>
<div class="col-xs-12">
<div class="caption">
<ul class="nav nav-pills nav-stacked">
<li role="presentation" class="active">Overview</li>
<li role="presentation" class="">Personal Information</li>
<li role="presentation" class="">Skills</li>
</ul>
</div>
</div>
</div>
</div>
</div>
<!-- Information Sections -->
<div class="col-md-8 col-md-offset-3 information">
<div class="overview show" id="overview">
<h2 class="line">Overview</h2>
<p class="lead">{{ user.userprofile.overview }}</p>
<a data-placement="bottom" title="update overview" class="fa fa-edit" data-toggle="modal" data-tooltip="tooltip" data-target=".overview_info"></a>
</div>
<div class="personal-info" id="personal-information">
<h2 class="line">Personal Information</h2>
<p class="lead">City: {{ user.userprofile.city }}</p>
<p class="lead">Phone Number: 0{{ user.userprofile.phone }}</p>
<p class="lead">Sex: {{ user.userprofile.sex }}</p>
<a data-placement="bottom" title="update personal information" class="fa fa-edit" data-toggle="modal" data-tooltip="tooltip" data-target=".personal_info"></a>
</div>
<div class="skill" id="my-skills">
<h2 class="line">Skills:</h2>
<p class="lead">{{ user.userprofile.skill }}</p>
<a data-placement="bottom" title="update skills" class="fa fa-edit" data-toggle="modal" data-tooltip="tooltip" data-target=".skills"></a>
</div>
</div>
<!-- get all questions -->
{% if user_prof.userasking_set.all %}
<div class="col-md-8 col-md-offset-3 user_questions">
<h2 class="line">All Questions You Asked</h2>
{% for questions in user_prof.userasking_set.all %}
<p>{{ questions.title }}</p>
{% endfor %}
</div>
{% endif %}
<!-- get favourites -->
{% if get_favourite %}
<div class="col-md-8 col-md-offset-3 user_questions">
<h2 class="line">Favourites</h2>
{% for fav in get_favourite %}
<p>{{ fav.title }}</p>
{% endfor %}
</div>
{% endif %}
</div>
{% include 'accounts/information_form.html' %}
</div>
{% include 'base_footer.html' %}
{% endif %}
{% endblock %}
accounts/views.py
#method_decorator(login_required, name='dispatch')
# view profile page
class ViewProfile(UpdateView):
queryset = UserProfile.objects.all()
template_name = 'accounts/profile.html'
form_class = UpdateInfoForm
slug_field = 'slug'
slug_url_kwarg = 'user_slug'
def get_success_url(self):
return reverse_lazy('accounts:view_profile', kwargs={'user_slug': self.request.user.userprofile.slug})
def get_context_data(self, **kwargs):
self.request.session['switch_comment'] = False
context = super().get_context_data(**kwargs)
user_prof = UserProfile.objects.get(user=self.request.user)
context['user_prof'] = user_prof
context['get_favourite'] = User.objects.get(username=self.request.user.username).favorite.all()
return context
def form_valid(self, form):
form.instance.user_slug = self.request.user.userprofile.slug
self.object = form.save()
return super().form_valid(form)
community/views.py
# List all questions + search
class UserQuestions(ListView):
template_name = 'community/user_questions.html'
context_object_name = 'all_objects'
queryset = UserAsking
def get_context_data(self, object_list=queryset, **kwargs):
context = super().get_context_data(**kwargs)
# paginator
context['all_objects'] = UserAsking.objects.all()
paginator = Paginator(context['all_objects'], 5)
page_number = self.request.GET.get('page_number')
context['all_objects'] = paginator.get_page(page_number)
# search
context['query'] = self.request.GET.get("query", '')
if context['query']:
all_objects = UserAsking.objects.all().order_by('-date')
context['all_objects'] = all_objects.filter(
Q(title__contains=self.request.GET['query']) |
Q(question__contains=self.request.GET['query']) |
Q(field__contains=self.request.GET['query'])
)
return context
community/user_questions.py
{% extends 'base.html' %}
{% block title %} All Questions That People Asked {% endblock %}
{% block body %}
{% if request.user.is_authenticated %}
<div class="all-questions">
<div class="container">
<div class="fl-left hidden-sm hidden-xs">
<h2>All Questions</h2>
</div>
<div class="fl-right hidden-sm hidden-xs">
Ask Question
</div>
<div class="clear"></div>
<div class="row">
<div class="add-q">
<div class="col-sm-12 visible-sm-block visible-xs-block">
<h2>All Questions</h2>
</div>
<div class="col-sm-12 visible-sm-block visible-xs-block">
Ask Question
</div>
</div>
{% if all_objects %}
<div class="col-sm-12">
<div class="questions">
{% for post in all_objects %}
<div class="q_section">
<a class="text-primary title" href="{% url 'community:question_view' post.ask_slug %}">{{ post.title }}</a>
<p class="field">{{ post.field }}</p>
<div class="info fl-right">
<span class="time">{{ post.date }}</span> |
<a href="{% url 'accounts:view_profile' post.userprofile.slug %}" style="font-size:14px">
{% if post.userprofile.user.first_name != '' %}
{{ post.userprofile.user.first_name }}
{% else %}
User
{% endif %}
<img class="logo-image" style="width:25px;height: 25px" src="
{% if request.user.userprofile.logo %}
{{ request.user.userprofile.logo.url }}
{% else %}
{% load static %}
{% static 'index/images/default-logo.jpg' %}
{% endif %}
">
</a>
</div>
<div class="">
<!--a class="btn btn-primary btn-lg" href="{# {% url 'community:delete_post' post.id %} #}">
<i class="fa fa-trash x2"></i>
</a-->
</div>
</div>
{% endfor %}
</div>
</div>
{% else %}
<h2 class="text-center text-info">No Questions</h2>
{% endif %}
</div>
<!-- Pagination -->
{% if all_objects %}
<div class="pagination">
<span class="step-links">
{% if all_objects.has_previous %}
« first
previous
{% endif %}
<span class="current">
Page {{ all_objects.number }} of {{ all_objects.paginator.num_pages }}.
</span>
{% if all_objects.has_next %}
next
last »
{% endif %}
</span>
</div>
{% endif %}
</div>
</div>
{% include 'base_footer.html' %}
{% endif %}
{% endblock %}

Django page navigation- home list not visible

I am super new to Dango; pardon me for a rookie question :)
I am learning Django by creating a "Note taking app". This is how the application home page looks.
When I click on any of the notes from the note list, it opens the details on the right-side page. But the problem is it wipes-out the left-hand side note list. To reload the list I need to click on the Home link again. The expected behavior is, it should retain the note-list on the left side as well as show the details on the right frame.
urls.py
from django.urls import path
from .views import NoteListView, NoteDetailView, NoteCreateView, NoteUpdateView, NoteDeleteView
from . import views
urlpatterns = [
path('', NoteListView.as_view(), name='lekha-home'),
path('note/<int:pk>/', NoteDetailView.as_view(), name='note-detail'),
path('note/new/', NoteCreateView.as_view(), name='note-create'),
path('note/<int:pk>/update', NoteUpdateView.as_view(), name='note-update'),
path('note/<int:pk>/delete', NoteDeleteView.as_view(), name='note-delete'),
path('about/', views.about, name='lekha-about'),
]
enter code here
views.py
class NoteListView(ListView):
model = Note
template_name = 'lekha/home.html'
context_object_name = 'notes'
ordering = ['-date_created']
class NoteDetailView(DetailView):
model = Note
# success_url = 'lekha/note_detail.html'
class NoteCreateView(LoginRequiredMixin, CreateView):
model = Note
fields = ['title', 'content']
def form_valid(self, form):
form.instance.author = self.request.user
return super().form_valid(form)
home.html
{% extends "lekha/base.html" %}
{% block content %}
{% for note in notes %}
<div class="list-group">
{{ note.title }}
</div>
{% endfor %}
{% endblock content %}
note_detail.html
{% extends "lekha/base.html" %}
{% block content2 %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-8" href="#">{{ object.author }}</a>
<small class="text-muted">{{ object.date_created|date:"F d, Y" }}</small>
{% if object.author == user %}
<a class="btn float-right btn-secondary ml-1 btn-sm" href="{% url 'note-update' object.id %} ">Update</a>
<a class="btn float-right btn-danger ml-1 btn-sm" href="{% url 'note-delete' object.id %} ">Delete</a>
{% endif %}
</div>
<h4 class="article-title">{{ object.title }}</h4>
<hr>
<p class="article-content">{{ object.content }}</p>
</div>
</article>
{% endblock content2 %}
And this is how I am calling it in base.html
<main role="main" class="container-fluid px-2">
<div class="row">
<div class="col-md-3">
<div class="content-section">
<h4>Notes</h4>
{% block content %}{% endblock %}
</div>
</div>
<div class="col-md-8">
{% block content2 %}{% endblock %}
</div>
</div>
</main>
Sorry for the detailed post. I would appreciate any pointers. Thanks!
Welcome to Django!
Your template note_detail.html extends base.html, which doesn't contain the HTML for the list of notes, and note_detail.html doesn't add the list, so that's why it's not showing up - you haven't added it!
To do this, you need the same {% block content %} from home.html in note_detail.html, and you also need to manually pass a notes context variable to the template. You get that for free with the ListView class.
First, the change to the template:
note_detail.html
{% extends "lekha/base.html" %}
{% block content %}
{% for note in notes %}
<div class="list-group">
{{ note.title }}
</div>
{% endfor %}
{% endblock content %}
{% block content2 %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-8" href="#">{{ object.author }}</a>
<small class="text-muted">{{ object.date_created|date:"F d, Y" }}</small>
{% if object.author == user %}
<a class="btn float-right btn-secondary ml-1 btn-sm" href="{% url 'note-update' object.id %} ">Update</a>
<a class="btn float-right btn-danger ml-1 btn-sm" href="{% url 'note-delete' object.id %} ">Delete</a>
{% endif %}
</div>
<h4 class="article-title">{{ object.title }}</h4>
<hr>
<p class="article-content">{{ object.content }}</p>
</div>
</article>
{% endblock content2 %}
And the change to the view:
views.py
class NoteListView(ListView):
model = Note
template_name = 'lekha/home.html'
context_object_name = 'notes'
ordering = ['-date_created']
class NoteDetailView(DetailView):
model = Note
def get_context_data(self):
data = super().get_context_data
data['notes'] = Note.objects.all().order_by('-date_created')
One last tip: to keep your HTML templates "DRY," you should really extract the list of notes into a separate html template (often called a partial) that you can plug into multiple other templates. Your template setup would look like this:
partials/all_notes.html
{% for note in notes %}
<div class="list-group">
{{ note.title }}
</div>
{% endfor %}
home.html
{% extends "lekha/base.html" %}
{% block content %}
{% include 'lekha/partials/all_notes.html' %}
{% endblock content %}
note_detail.html
{% extends "lekha/base.html" %}
{% block content %}
{% include 'lekha/partials/all_notes.html' %}
{% endblock content %}
{% block content2 %}
<article class="media content-section">
<div class="media-body">
<div class="article-metadata">
<a class="mr-8" href="#">{{ object.author }}</a>
<small class="text-muted">{{ object.date_created|date:"F d, Y" }}</small>
{% if object.author == user %}
<a class="btn float-right btn-secondary ml-1 btn-sm" href="{% url 'note-update' object.id %} ">Update</a>
<a class="btn float-right btn-danger ml-1 btn-sm" href="{% url 'note-delete' object.id %} ">Delete</a>
{% endif %}
</div>
<h4 class="article-title">{{ object.title }}</h4>
<hr>
<p class="article-content">{{ object.content }}</p>
</div>
</article>
{% endblock content2 %}
base.html
<main role="main" class="container-fluid px-2">
<div class="row">
<div class="col-md-3">
<div class="content-section">
<h4>Notes</h4>
{% block content %}{% endblock %}
</div>
</div>
<div class="col-md-8">
{% block content2 %}{% endblock %}
</div>
</div>
</main>

Returning many objects on html page - Django 2.0

I am returning the "comentarios" objects of the database through a for, but since the display of these objects takes up a lot of space in the html page, I would like to know how to divide the objects into more lists or into a hidden space, since when they pass from seven comments they exceed the size of the body.
template.html
{% extends 'baseR.html' %}
{% load static %}
{% block title %} Comentários - SMILE 3D {% endblock %}
{% block tamanho %} 2000px {% endblock %}
{% load bootstrap %}
{% block main %}
<div class="row b2">
<div class="col-1"></div>
<div class="col-10">
<h3 style="color:royalblue; font-weight:bold;">Pregão: </h3>
<hr>
<h2>{{msg}}</h2>
<br>
<ul style="list-sytle:none;">
<div class="container pregoes">
<li style="list-style:none;">
<p><strong>Dono: </strong>{{pregoe.usuario}}</p>
<p><strong>Tipo do pregão: </strong>{{ pregoe.tipo }}</p>
<p><strong>Dente: </strong>{{ pregoe.dente }}</p>
<p><strong>Cor: </strong>{{ pregoe.cor }}</p>
<p><strong>Escala: </strong>{{ pregoe.escala }}</p>
<p><strong>Material: </strong>{{ pregoe.material }}</p>
<p><strong>Observações: </strong>{{ pregoe.extra }}</p>
<p><strong>Preço inicial: </strong>R${{ pregoe.preco }}</p>
<p><strong>Data de registro: </strong><em>{{ pregoe.data }}</em></p>
<p><strong>Prazo: </strong><em>{{ pregoe.prazo }}</em></p>
</li>
</div>
<br>
<hr>
**<h3>Comentários: </h3>
{% for comentario in comentarios %}
<div class="container" style="background-color:gainsboro; padding-bottom:2px; padding-top:10px;">
<i class="far fa-times-circle" style="float: right;"></i>
<p><strong>{{comentario.user}}</strong> </p>
<p style="float:right;">{{comentario.comentario}}</p>
<div class="circle1">
<img src="../../media/{{comentario.user.foto}}" class="fotoPerfil img-fluid" style="max-width: 80px;">
</div>
</div>
<br>
{% endfor %}**
<br>
{{msg}}
NOVO COMENTÁRIO <i class="far fa-comment"></i>
</ul>
</div>
</div>
{% endblock %}
views.py
#login_required
def listaComentarios(request, id1, id2):
user = get_object_or_404(CustomUser, pk=id2)
pregao = get_object_or_404(Pregao, pk=id1)
comentarios = Comentario.objects.all().filter(pregao=pregao)
if user == pregao.usuario:
return render(request, 'comentarios/lista-comentarios-dono.html', {'comentarios': comentarios, 'pregoe': pregao})
return render(request, 'comentarios/lista-comentarios.html', {'comentarios': comentarios, 'pregoe': pregao})
You need to add pagination and you will receive your queryset by parts.
You can get information on about in official Django docs.
https://docs.djangoproject.com/en/2.1/topics/pagination/#using-paginator-in-a-view