我想編寫一個視圖來將某些模型字段值重置爲默認值。我如何獲得默認模型字段值?django獲取默認模型字段值
class Foo(models.Model):
bar_field = models.CharField(blank=True, default='bar')
所以我要的是:
def reset(request, id):
obj = get_object_or_404(Foo, id=id)
obj.bar_field = # logic to get default from model field
obj.save()
...
更具體一點,你到底想做什麼? – sebb
已更新@SebastianBurzyński – Goran
Duplicate:https://stackoverflow.com/questions/1308332/how-do-i-get-the-default-value-for-a-field-in-a-django-model – ThePhi