所以,我得到了三个类:
class User(...):
#... other fields
name = models.CharField()
class Equipment(...):
#... other fields
inUse = models.Boolean(default=False)
class Ticket(...):
#... Other fields
user = models.ForeignKey(...)
equipment = models.ForeignKey(...)
ended = models.Boolean(default=False)
现在,当我创建新的Ticket
时;在使用中";属性更改为True,因此我不能将同一个Equipment
赋予多个User
。问题是当我将CCD_ 4设置为"0"时;结束";我仍然可以将其更改为"不";结束";。我希望一旦我设置了";结束";Ticket
的属性设置为True。
PS:当设置新的CCD_ 7或将其更改为"保存"时,我正在重写方法save以在CCD_;结束";。
admin.py
from django.contrib import admin
from .models import Equipamento, TipoEquipamento, Funcionario, Setor, Ticket
# Register your models here.
class EquipamentoAdmin(admin.ModelAdmin):
list_display = ['codigo', 'categoria', 'descricao', 'ativo', 'emUso']
search_fields = ['codigo', 'descricao']
class FuncionarioAdmin(admin.ModelAdmin):
list_display = ['nome', 'setor', 'email']
search_fields = ['codigo', 'nome']
class TicketAdmin(admin.ModelAdmin):
list_display = ['id', 'get_user_name', 'get_equipment_name', 'dataDevolucao', 'finalizado']
autocomplete_fields = ['usuario', 'equipamento']
def get_user_name(self, obj):
return obj.usuario.nome
def get_equipment_name(self, obj):
return obj.equipamento.descricao
get_user_name.short_description = 'Funcionario'
get_equipment_name.short_description = 'Equipamento'
愚蠢的问题,几分钟后我意识到我可以设置一个字段,比如"可以更改";在模型中,这样当我更改Status
时,该字段将被设置为false,并且我将无法再更改该模型。达阿,谢谢你。