如何在Django中更改代理模型上字段的最大长度



我正在做一个公告板项目。我有两个Django模型类:

from ckeditor.fields import RichTextField
...
class Bulletin(models.Model):
# other fields...
content = RichTextField('Content (Don't use this and content image)',
max_length=5000, blank=True,
null=True) 
# other classes...
class QuoteManager(models.Manager):
def get_queryset(self):
return super(QuoteManager, self).get_queryset().filter(
bulletin_type=BulletinType.QUOTE.name)
class Quote(Bulletin):
class Meta:
proxy = True
objects = QuoteManager()
def save(self, *args, **kwargs):
self.bulletin_type = BulletinType.QUOTE.name
super(Quote, self).save(*args, **kwargs)

这允许我将我的所有代理类保持在同一个DB中,并具有与我的基本"代理"相同的字段;公告";班

我想做的是修改Quote代理类,使其max_length为200。我该怎么做?

我试过什么

我试着添加";内容";到代理类,这是一个名称冲突。

我尝试添加一个名为";quote_content;到代理类作为一种变通方法,但这也失败了,因为您无法在代理类中创建字段。

一个完美的解决方案允许我保留代理类,但仍然可以修改max_length。这样的想法可能吗?

您可以尝试使用,forms

我不认为代理模型会允许你这样做

最新更新