Django管理员 - 删除自我引用字段的“添加另一个”按钮

时间:2015-06-19 00:15:14

标签: python django django-admin

我有一个Django项目,其中包含一个带有可选自引用ForeignKey字段的模型类。部分片段:

class Site(models.model):
    name = models.CharField(max_length=100)
    parent_site = models.ForeignKey('self', null=True, blank=True)

我正在使用Django管理站点来创建新对象。对于此课程的管理员表单,我要禁用parent_site字段旁边的“添加其他... ”按钮(即,当您创建新网站时,您可以打开弹出窗口以创建另一个新站点作为父站点。

我无法从用户中删除has_add_permission,因为他们需要将其放在当前的添加视图中。我不介意从添加和更改视图中删除该功能,但限制删除到添加视图会很有帮助。

我无法弄清楚如何使用内联字段类来实现此目的,或formfield_for_foreignkey或自定义ModelForm。任何人都比在自定义表单模板上使用JavaScript更优雅的解决方案吗?

1 个答案:

答案 0 :(得分:1)

没有css hacks添加到管理员类:

    Function CUSTOMAVERAGE(rng As Range)
Dim cell As Range, suma As Double, sk As Double, i As Double, vidurkis As Double, max As Double, dup As Double, dupp As Double, down As Double, downn As Double, text1 As String

 suma = 0
For Each cell In rng
    suma = suma + cell.Value
    sk = sk + 1
Next cell
vidurkis = suma / sk



max = 0
For Each cell In rng
    If max < cell.Value Then
    max = cell.Value
    End If
Next cell
max = max

min = max
For Each cell In rng
    If min > cell.Value Then
    min = cell.Value
    End If
Next cell
min = min

dupp = 0
dup = 0
sk = 0
For Each cell In rng
    If vidurkis < cell.Value Then
    dupp = dupp + cell.Value
    sk = sk + 1
    End If
Next cell
dup = dupp / sk



downn = 0
down = 0
sk = 0
For Each cell In rng
    If vidurkis > cell.Value Then
    downn = downn + cell.Value
    sk = sk + 1
    End If
Next cell
down = downn / sk




text1 = "V=" & CStr(vidurkis) & " Min=" & CStr(min) & " Max=" & CStr(max) & " Dup=" & CStr(dup) & " Ddown=" & CStr(down)
CUSTOMAVERAGE = text1
End Function

或在admin.py中尝试此操作(对于较旧的django版本):

max_num=0