django-smart-selects
django-smart-selects copied to clipboard
Creating something like a MultipleChainedForeignKey to allow multiple chained fields for a same ForeignKey Field
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]
- [ x] This issue is not about installing previous versions of django-smart-selects older than 1.2.8. I understand that previous versions are insecure and will not receive any support whatsoever.
- [ x ] I have verified that that issue exists against the
masterbranch of django-smart-selects. - [ x ] I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
- [ ] I have debugged the issue to the
smart_selectsapp. - [ x ] I have reduced the issue to the simplest possible case.
- [ ] I have included all relevant sections of
models.py,forms.py, andviews.pywith problems. - [ x ] I have used GitHub Flavored Markdown to style all of my posted code.
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
)