【发布时间】:2021-10-08 14:02:25
【问题描述】:
我正在使用 Django 和 PostgreSQL 开发网络,我正在使用应用程序 django-tables2 创建 HTML 表。
class SampleTable(ColumnShiftTableBootstrap4):
class Meta:
model = Sample
fields = ("name", "sample_id_sex", "pools", "indexes", "gene_cand_lists",)
我的数据库收集下一代测序 (NGS) 数据。 sample_id_sex 是外键(1:N 关系),而pools、indexes 和gene_cand_lists 是多对多字段,这三行的组合是唯一的:换句话说,它们是相关的。
我的问题是,在每一行中,默认情况下对值进行排序。例如,样本 X 属于池 CES001,具有索引 B2 和基因列表 list3,但它也属于具有索引 A1 和 list1 的池 CES002。在表格中,它们应如下所示(, 作为多对多列中的分隔符):
| sample | sex | pools | indexes | gene_lists |
|---|---|---|---|---|
| 12-009 | male | CES001, CES002 | B2, A1 | list3, list1 |
但它们看起来像这样:
| sample | sex | pools | indexes | gene_lists |
|---|---|---|---|---|
| 12-009 | male | CES001, CES002 | A1, B2 | list1, list3 |
这三个字段之间的关系被打破了。有没有办法纠正这个问题?分隔符可以是换行符而不是逗号?
编辑:我认为这个问题还不够清楚。样本表的型号为:
class Sample(models.Model):
id_sample = models.AutoField(primary_key=True)
name = models.CharField(unique=True, max_length=20)
indexes = models.ManyToManyField(Index, through='SamplePoolIndexCand', blank=True)
pools = models.ManyToManyField(Index, through='SamplePoolIndexCand', blank=True)
gene_lists = models.ManyToManyField(Index, through='SamplePoolIndexCand', blank=True)
还有中间表:
class SamplePoolIndexCand(models.Model):
sample_id = models.ForeignKey(Sample, null=True, blank=True, on_delete=models.CASCADE, db_column='id_sample',
verbose_name='Mostra')
pool_id = models.ForeignKey(Pool, null=True, blank=True, on_delete=models.CASCADE, db_column='id_pool',
verbose_name='Pool')
index_id = models.ForeignKey(Index, null=True, blank=True, on_delete=models.CASCADE,
db_column='id_index', verbose_name='Índex')
gene_cand_list_id = models.ForeignKey(GeneCandList, null=True, blank=True, on_delete=models.CASCADE,
db_column='id_gene_cand_list', verbose_name='Llista de gens candidats')
【问题讨论】:
标签: django database postgresql many-to-many django-tables2