0

I have a simple model being displayed in the admin. In the add view I have 4 fields, with the first field being a foreign key to user. I need to:

  1. Pre-populate the user field.
  2. Make the field read only.

I cannot find any documentation on this. I looked at the following links:

EDIT: I found a solution for my first problem here; Djanjo admin: Prefill data when clicking the add-another button next to a ForeignKey dropdown

Community
  • 1
  • 1
tseboho
  • 77
  • 10

1 Answers1

0

Here, you need to add jQuery for prepopulate that particular field. Create your own js script file inside static directory of your app & just extend change_form.html of admin site. For example if you want add script.js script into your add template, your extended change_form.html will look like as follows:

{% extends 'admin/change_form.html' %}
{% load static %}
{% block admin_change_form_document_ready %}
{{ block.super }}
<script type="text/javascript" src="{% static 'qb/js/formset_handlers.js' %}"></script>
{% endblock %}