3 ms·
Why wouldn't you just make the it an abstract base model without any fields? If that's not what you want though you should be able to get that behavior using mu
by almost 17y ago
Why wouldn't you just make the it an abstract base model without any fields? If that's not what you want though you should be able to get that behavior using multiple inheritance:
class AlwaysUpdate(object):
def save(self, *args, **kwargs):
if self.pk:
kwargs['force_update'] = True
kwargs['force_insert'] = False
else:
kwargs['force_insert'] = True
kwargs['force_update'] = False
return super(AlwaysUpdate, self).save(*args, **kwargs)
class MyModel(AlwaysUpdate, models.Model):
pass # model def here