how to get data from model objects in django?

You can print the object_id value in your template, that value is passed by default by the change_view method, you can always override this method if you want to pass extra data to your change_view template too:

So one way to do what you want to do is this, you can print the object_id in a hidden input so the value will be passed to your view by the form submit:

{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block content %}
    {{ block.super }}
    <form action="{% url 'post_tweet' %}" method="POST">
        {% csrf_token %}
        <input type="hidden" name="movie_id" value="{{ object_id }}">
        <input type="submit" value="Tweet" name="add_tweet">
{% endblock %}

Now you can get the instance of the object and get the title and the image of a movie in your tweet view by searching by its id.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top