jazzband / django-smart-selects

chained and grouped selects for django forms
https://django-smart-selects.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.1k stars 348 forks source link

Creating something like a MultipleChainedForeignKey to allow multiple chained fields for a same ForeignKey Field #316

Open luishenriquesb opened 3 years ago

luishenriquesb commented 3 years ago

You MUST use this template when reporting issues. Please make sure you follow the checklist and fill in all of the information sections below.


All versions of django-smart-selects prior to version 1.2.8 are vulnerable to an XSS attack as detailed in issue 171. As a result, all previous versions have been removed from PyPI to prevent users from installing insecure versions. All users are urged to upgrade as soon as possible.

Checklist

Put an x in the bracket when you have completed each task, like this: [x]

Steps to reproduce

Actual behavior

The ChainedForeignKey allows chained just one field on the model referenced. I've already use this feature like that:

class ModeloSecao(models.Model):
    id_modelo_secao = models.AutoField(primary_key=True)
    categoria = models.ForeignKey('Categoria',
                                  on_delete=models.CASCADE)
    estruturas = models.ManyToManyField(
                                'Estrutura',)
class EstruturaSecao(models.Model):
    id_estrutura_secao = models.AutoField(primary_key=True)
    estrutura = models.ForeignKey('Estrutura',
                                  on_delete=models.CASCADE)
    categoria = models.ForeignKey('Categoria',
                                  on_delete=models.CASCADE)
    modelo_padrao = ChainedForeignKey(
                ModeloSecao,
                chained_field='categoria',
                chained_model_field='categoria',
                show_all=False,
                auto_choose=True,
                sort=True,
                on_delete=models.DO_NOTHING
             )

Expected behavior

it's would be really good if I could have a model using more than one field. I don't know how exactly this might be done. Maybe creating something like MultipleChainedForeignKey. Something like that:

class ModeloSecao(models.Model):
    id_modelo_secao = models.AutoField(primary_key=True)
    categoria = models.ForeignKey('Categoria',
                                  on_delete=models.CASCADE)
    estruturas = models.ManyToManyField(
                                'Estrutura',)
class EstruturaSecao(models.Model):
    id_estrutura_secao = models.AutoField(primary_key=True)
    estrutura = models.ForeignKey('Estrutura',
                                  on_delete=models.CASCADE)
    categoria = models.ForeignKey('Categoria',
                                  on_delete=models.CASCADE)
    modelo_padrao = MultipleChainedForeignKey(
                ModeloSecao,
                chained_fields=('categoria', 'estrutura')
                chained_model_fields=('estrutura','estruturas'),
                show_all=False,
                auto_choose=True,
                sort=True,
                on_delete=models.DO_NOTHING
             )