我有一个 Django 模型,如下所示:
class LocationMaster(models.Model):
id = models.AutoField(primary_key=True)
open_date = models.DateField(blank=True, null=True)
months_open = models.DecimalField(max_digits=18, decimal_places=2, blank=True, null=True) # Calculated column in SQL Server
maturity = models.CharField(max_length=50, blank=True) # Calculated column in SQL Server
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
# ?? Something here
super(LocationMaster, self).save(force_insert, force_update, using, update_field)
我的两列是 SQL Server 计算列。我想在我的应用程序中显示这些列,包括在管理中,但不插入或更新这些列,因为它们是计算出来的。如果没有修改我的模型,我会收到此错误:
('42000', '[42000] [FreeTDS][SQL Server]The column "months_open" cannot be modified because it is either a computed column or is the result of a UNION operator. (271) (SQLExecDirectW)')
如何修改我的模型以便 Django 不会尝试插入或更新这些特定列?