WebOct 22, 2011 · 3 Answers. Do not set self.readonly_fields to avoid thread issues. Instead override get_readonly_fields method: def get_readonly_fields (self, request, obj=None): if obj: # obj is not None, so this is an edit return ['third_party_id',] # Return a list or tuple of readonly fields' names else: # This is an addition return [] Very cool didn't know ... WebOct 10, 2024 · THE GOAL: Display a request-specific, read-only user_id on a django admin form when creating and updating a resource.. This display should be a readonly field (readonly, NOT disabled).The user_id displayed is derived from the requesting user (request.user) so the initial value is set from that.. Following this post, we should simply …
Django Admin Form: Set the default value of a readonly field
WebFeb 11, 2024 · 3. I just would like to find an answer of how to change label / caption of readonly item in Django admin. When the field / form is not readonly then it is rather easy to do like: class MyModelAdmin (admin.ModelAdmin): readonly_fields= ( 'field_ro_1', 'field_ro_2', ) def get_form (self, request, obj=None, change=False, **kwargs): form = … Web我想创建的字段将与当前管理员谁是登录的电子邮件自动填充,它应该是只读字段 我试过这个: admin.py. from django.contrib import admin from support.models import Ticket class TicketAdmin(admin.ModelAdmin): def get_form(self, request, obj=None, **kwargs): form = super().get_form(request, obj, **kwargs) form.base_fields['created_by'].initial = … elk grove memory care
django - 在管理界面中使用來自其他模型的值填充 django …
WebMar 2, 2024 · from django.contrib.admin.options import ModelAdmin, TabularInline, StackedInline from django.utils.translation import gettext_lazy as _ from .models import Image, Product class ImageAdminInline(TabularInline): extra = 1 model = Image class ProductModelAdmin(ModelAdmin): inlines = ImageAdminInline, fields = 'title', class … WebNov 3, 2016 · I want to display my widget on the field at django admin when the field is readonly. admin.py. class AudioTrackAdminInline (admin.StackedInline): model = AudioTrack form = AudioTrackForm readonly_fields = ('file',) forms.py. class AudioTrackForm (forms.ModelForm): class Meta: model = AudioTrack widgets = { 'file': … WebOne of the most powerful parts of Django is the automatic admin interface. It reads metadata from your models to provide a quick, model-centric interface where trusted … Admin actions¶ The basic workflow of Django’s admin is, in a nutshell, “select … We would like to show you a description here but the site won’t allow us. forcing roku software download