我有一个模型:
class MyModel(models.Model):
name = [...]
surname = [...]
symbol = models.CharField(unique=True)
[...]
当用户在管理面板中单击“新建”时,我想在符号字段中自动生成一些数据。例如:
def generate_symbol():
last_symbol = MyModel.objects.all().order_by('symbol')[0]
return "%d" % (last_symbol + 1)
怎么做?