Displaying the content of a model field when a link is clicked on the same template

Hello fellas!

I’m building a page where I have rendered three objects from a model into a template. I want to be able to display the content of the title on the same page when I click the links. But I have absolutely no idea how to even start.

Can someone please guide me towards the right approach?

In uploaded image, I have rendered the title, date created and the user whom created the content. The titles are linked to another model field called response, which is a API response that I have saved into the database. I would like to display the API response when the titles are clicked on the right side, which represent an A4-sheet.

My model:

class AdminPageModels(models.Model):
username = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True)

title = models.CharField(_("Title"), max_length=50, null=False, blank=False, default="")
age_group = models.IntegerField(_("Age"), null=True, blank=False)
nr_image = models.PositiveBigIntegerField(_("Images"), null=True, blank=True, validators=[MinValueValidator(1), MaxValueValidator(20)], default=1)

# API settings 
temperature = models.DecimalField(_("Temperature"), null=True, blank=False, max_digits=2, decimal_places=1, validators=[MinValueValidator(0), MaxValueValidator(1)])
max_length = models.PositiveIntegerField(_("Max length"), null=True, blank=False, validators=[MinValueValidator(1), MaxValueValidator(4000)])
top_p = models.DecimalField(_("Top P"), null=True, blank=True, max_digits=2, decimal_places=1, validators=[MinValueValidator(0), MaxValueValidator(1)])
frequency_penalty = models.DecimalField(_("Frequency penalty"), null=True, blank=True, max_digits=2, decimal_places=1, validators=[MinValueValidator(-2), MaxValueValidator(2)])
best_of = models.PositiveIntegerField(_("Best of"), null=True, blank=True, validators=[MinValueValidator(1), MaxValueValidator(20)])
presence_penalty = models.DecimalField(_("Presence penalty"), null=True, blank=True, max_digits=2, decimal_places=1 ,validators=[MinValueValidator(-2), MaxValueValidator(2)])

image_description = models.CharField(_("Image description"), null=True, blank=True, max_length=500, default="")
promt = models.TextField(_("Promt"), null=True, blank=False)
date_created = models.DateTimeField(auto_now_add=True, null=True)
response = models.TextField(_("Response"), null=True, blank=False)

def __str__(self):
    return self.title


The template:

{% block content %}

{% if request.user.is_authenticated %}

    <section class="page__background">

            <section class="collections__page__LHS">
                <div class="collections">
                    <table class="table">
                        <tr class="table_headerRow">
                        {% for header in AdminPageModels_instance %}
                            <tr class="rows">
                        {% endfor %}


            <section class="collections__page__RHS">
                <section class="A4_sheet">

{% else %}

    <section class="admin__main__page__background">
        <div class="restricted__page">
            <p class="page__text">You don't have acces to this page</p>

{% endif %}

{% endblock content %}


The view function:

def admin_homepage(request):
# handle the case when the response is None or not generated
chatbot = None
user_input_promt = None
user_input_temperature = None
user_input_maxtokens = None
user_input_topP = None
user_input_frequency_penalty = None

if request.method == "POST":
    form = AdminPageModelsForm(request.POST)
    if form.is_valid():
        user_input_promt = form.cleaned_data["promt"]
        user_input_temperature = float(form.cleaned_data["temperature"])
        user_input_maxtokens = int(form.cleaned_data["max_length"])
        user_input_topP = float(form.cleaned_data["top_p"])
        user_input_frequency_penalty = float(form.cleaned_data["frequency_penalty"])
        user_input_presence_penalty = float(form.cleaned_data["presence_penalty"])
        user_input_best_of = int(form.cleaned_data["best_of"])
        chatbot = chatbot_response(user_input_promt,
    form = AdminPageModelsForm()
context = {"form": form, "chatbot": chatbot}
return render(request, "admin_ui_app/admin.html", context)

def collections(request):
AdminPageModels_instance = AdminPageModels.objects.all()

context = {"AdminPageModels_instance": AdminPageModels_instance}
return render(request, "admin_ui_app/story_collection.html", context)

Side note: When you’re posting code, templates, error messages, etc, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code (or template, etc), then another line of ```. This forces the forum software to keep your code properly formatted.

If you’re looking at doing this without a full page refresh you’ll need to use some JavaScript to make an AJAX call to a view to retrieve the html fragment to be used to update the current page.

If a full page reload is acceptable, then you can render the title on the left as a link to a view that will rerender that page with the selected content.