Skip to content

Error when using "through" intermediate model #187

Description

@eudaldt

I think this was asked before but is it possible to define my own intermediate model with sortedm2m using through? In my case I have this model:

class Sample(models.Model):
   id_sample = models.AutoField(primary_key=True)
   name = models.CharField(unique=True, max_length=20)
   indexes = SortedManyToManyField(Index, through='SamplePoolIndexCand', blank=True)
   pools = SortedManyToManyField(Index, through='SamplePoolIndexCand', blank=True)
   gene_lists = SortedManyToManyField(Index, through='SamplePoolIndexCand', blank=True)

The intermediate table:

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')

I got this error message:

AssertionError: The model is used as an intermediate model by '<class 'myproject.models.SamplePoolIndexCand'>' but has no defined '_sort_field_name' attribute

How can I solve this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions