0
我在管理員中創建一個只讀表格內聯,並且我無法擺脫狀態對象的此額外下拉列表。正如你所看到的,我只有3個readonly_fields,但是爲TaskStatus.status顯示了一個額外的字段,並且它是可編輯的。任何想法爲什麼?我確信我忽略了一些簡單的東西。Django TabularInline,只有readonly_fields,但我的FK對象仍然顯示並可編輯
class TaskStatusInline(admin.TabularInline):
model = TaskStatus
extra = 0
readonly_fields = [
'status_name',
"updated_by",
'timestamp'
]
can_delete = False
def has_add_permission(self, request, obj=None):
return False
def status_name(self, obj):
return obj.status.name
模型
class TaskStatus(models.Model):
class Meta:
ordering = ['-timestamp']
status = models.ForeignKey('status')
task = models.ForeignKey('Task', related_name="task_status")
timestamp = models.DateTimeField(auto_now_add=True)
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True)
class Status(models.Model):
class Meta:
unique_together = ['status', 'substatus']
verbose_name_plural = "status"
ordering = ['code']
name = models.CharField(max_length=50)
status = models.CharField(max_length=25)
substatus = models.CharField(max_length=25)
code = models.IntegerField()
添加list_display,並且只包括3場 – sebb
我加list_display具有相同的字段如你所說,仍然能看到同樣的結果... @sebb – whieronymus
您還沒有將「狀態」添加到readonly_fields? –