我认为以下代码解释了我正在尝试做的事情
from django.db import models
class MyBaseClass(models.Model):
type = models.IntegerField()
class Meta:
abstract = True
def save(self, *args, **kwargs):
self.type = #What Should I write here?#
self.type = self.class.type ?
super().save(*args, **kwargs)
class Model1(MyBaseClass):
TYPE = 1
class Model2(MyBaseClass):
TYPE = 2
我想确保以下断言有效:
instance1 = Model1.objects.create()
assert(instance1.type, 1)
instance2 = Model2.objects.create()
assert(instance1.type, 2)
我怎样才能使这项工作?谢谢。