class Service_Admin(admin.ModelAdmin):
save_as=True
change_form_template = "admin_template.html"
from django.db import connection
with connection.cursor() as cursor:
cursor.execute("SELECT * FROM some_table ")
gallery_add = cursor.fetchall()
{% extends "admin/change_form.html" %}
{% load i18n admin_urls %}
{% block inline_field_sets %}
{% for inline_admin_formset in inline_admin_formsets %}
{% include inline_admin_formset.opts.template %}
{% ifequal inline_admin_formset.formset.prefix 'block_name' %}
<select id='add_id'>
<b>{% for line in gallery_add %}
<option value='{{ line.id }}'>{{ line.name }}</option>
{% endfor %}</b>
</select>
{% endifequal%}
{% endfor %}
{% endblock %}
class Service_Admin(admin.ModelAdmin):
change_form_template = "admin_template.html"
def change_view(self, request, object_id, form_url='', extra_context=None):
extra_context = extra_context or {}
extra_context['gallery_add'] = "Нужное значение"
return super(Service_Admin, self).add_view(request, form_url, extra_context)