寻求设计django模型的帮助

Seeking help in designing django models

我正在寻找有关我正在工作的项目的 django 模型的一些反馈 on.So 我正在构建一个文档数据库,其中的文档可以分为 3 类 - GTO、EWR 和 [=这些文档中的 26=] 对应一个 well.Each 可以有多个文档与 it.The 相关联 用户可以上传和查看对应一个 well.Here 的文档 我的设计:

basedoc - class 保存文档的属性并将作为基础 class。

井 - class 保持井的属性。

GTO - 继承自 basedoc 并使用外键与井链接。

EWR - 继承自 basedoc 并使用外键与井链接。

QPR - 继承自 basedoc 并使用外键与孔链接。

class basedoc(models.Model):
    docfile = models.FileField(upload_to='documents/%Y/%m/%d')
    title = models.CharField("Doc Title",max_length=50)
    pub_date = models.DateTimeField('Date published',auto_now_add=True)
    remark = models.TextField(max_length=200,blank=True)
    publisher = models.ForeignKey(User)

    def __str__(self):
        return self.title

class wells(models.Model):
    well_name = models.CharField(max_length=20)
    well_loc = models.CharField(max_length=20)

    def __str__(self):
        return self.well_name

class GTO(basedoc):
    gto = models.ForeignKey(wells)
    pass

class EWR(basedoc):
    ewr = models.ForeignKey(wells)
    pass

class QPR(basedoc):
    qpr = models.ForeignKey(wells)
    pass

我最初使用 basedoc 作为抽象基础 class,但改变是因为我想 return 向用户提供所有文档的列表作为 view.Please 帮助我改进这个design.Thanks.

您可能需要不时检索 wells 的所有文档。或者您可能需要将文档从 GTO 移动到 EWR。为了提高效率,我不会使用 3 个表,而是使用 1 个。

您可以使用选项:

TYPE_CHOICES = (
    (1, 'GTO'),
    (2, 'EWR'),
    (3, 'QPR'),
)

class Document(models.Model):
    # ...your other fields here...
    type = models.IntegerField(choices=TYPE_CHOICES)