2
我正在规范与Django项目关联的数据库,并且将字段移动到不同的表中。作为实现过程的一部分,如果在我实际删除列之前尝试在添加新表后尝试使用旧属性,我想向我的同事抛出一个弃用警告。在Django模型中弃用字段
class Asset(Model):
model = models.CharField(max_length=64, blank=True, null=True)
part_number = models.CharField(max_length=32, blank=True, null=True) # this will be a redundant column to be deprecated
company = models.ForeignKey('Company', models.CASCADE, blank=True, null=True) # this will be a redundant column to be deprecated
# other database fields as attributes and class methods
我的理解是,我需要增加沿warnings.warn('<field name> is deprecated', DeprecationWarning)
在某处类线的东西,但我哪里会增加吗?
您可以将字段更改为属性并在那里处理警告,并在可能的情况下返回适当的值。 –