它允许您覆盖父模型的属性

它允许您覆盖父模型的属性

本文介绍了在Django - 模型继承 - 它允许您覆盖父模型的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找这样做:

class Place(models.Model):
 name = models.CharField(max_length=20)
 rating = models.DecimalField()

class LongNamedRestaurant(Place):  # Subclassing `Place`.
 name = models.CharField(max_length=255)  # Notice, I'm overriding `Place.name` to give it a longer length.
 food_type = models.CharField(max_length=25)

这是我想要的版本使用(虽然我可以接受任何建议):

This is the version I would like to use (although I'm open to any suggestion):http://docs.djangoproject.com/en/dev/topics/db/models/#id7

Django中是否支持此功能?如果没有,有没有办法实现类似的结果?

Is this supported in Django? If not, is there a way to achieve similar results?

推荐答案

不,:

这篇关于在Django - 模型继承 - 它允许您覆盖父模型的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 16:28