如何使用unique_together建立抽象模型? [英] How to have abstract model with unique_together?

查看:73
本文介绍了如何使用unique_together建立抽象模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我得到:

Error: One or more models did not validate:
test.test: "unique_together" refers to slug. This is not
in the same model as the unique_together statement.
test.test: "unique_together" refers to version. This is not
in the same model as the unique_together statement.

我有这样的模型定义:

class SlugVersion(models.Model):
    class Meta:
        abstract = True
        unique_together = (('slug', 'version'),)

    slug = models.CharField(db_index=True, max_length=10, editable=False)
    version = models.IntegerField(db_index=True, editable=False)

class Base(SlugVersion):
    name = models.CharField(max_length=10)

class Test(Base):
    test = models.IntegerField()

我有Django 1.3。

I have Django 1.3.

推荐答案

似乎是Django中的 bug

It seems it is a bug in Django.

这篇关于如何使用unique_together建立抽象模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆