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