The error is probably in your forms.py problably here self.fields['projeto'].queryset = Projeto.objects.filter( projeto=Projeto.nomeProjeto) . your atribute ‘projeto‘ don’t exist in Projeto.objects.filter(projeto=Projeto.nomeProjeto). to do the correct way I recomment you to look at how to filter a QuerySet in Django docs here: https://docs.djangoproject.com/en/3.1/topics/db/queries/#retrieving-specific-objects-with-filters ps: Do you speak portuguese? If so mail me, probably I can better help you. ----------------------------------------------------------------------------------------------------- Samuel Nogueira Bacelar GitHub: https://github.com/SamuelNoB Linkedin: https://www.linkedin.com/in/samuel-nogueira-87800b1aa/ ----------------------------------------------------------------------------------------------------- De: Gabriel Hi everyone! I am newbe in Django and I have a question. I am creating a multi-tenanci application and I need to filter the combobox according to projects created by logged users, but I have the following message: AttributeError at /requisitos/cadastrarRequisito/ 'WSGIRequest' object has no attribute 'projeto' My model: class Requisito (models.Model): nomeRequisito = models.CharField(max_length=30, verbose_name=('Nome do Requisito')) responsavel = models.CharField(max_length=30, verbose_name=('Responsável pelo Desenvolvimento')) código = models.CharField(max_length=20, verbose_name=('Código do Requisito')) projeto = models.ForeignKey(Projeto, _on_delete_=models.PROTECT) prioridade = models.CharField(max_length=10, verbose_name=('Prioridade do Requisito')) risco = models.CharField(max_length=10, verbose_name=('Risco do Requisito')) motivo = models.CharField(max_length=20, verbose_name=('Motivo do Requisito')) status = models.CharField(max_length=20, verbose_name=('Status do Requisito')) requisitosImpactados = models.CharField(max_length=100, verbose_name=('Requisitos Impactados')) user = models.ForeignKey(User, _on_delete_=models.CASCADE) estoriaUsuario = HTMLField() regrasNegocio = HTMLField() def __str__(self): return self.nomeRequisito Forms.py class CadastrarRequisitos(ModelForm): def __init__(self, projeto, *args, **kwargs): super(CadastrarRequisitos, self).__init__(*args, **kwargs) self.fields['projeto'].queryset = Projeto.objects.filter( projeto=Projeto.nomeProjeto) class Meta: model = Requisito fields = ['nomeRequisito', 'responsavel', 'código', 'projeto', 'prioridade', 'status', 'risco', 'motivo', 'requisitosImpactados', 'user', 'estoriaUsuario', 'regrasNegocio'] model of project class Projeto(models.Model): nomeProjeto = models.CharField(max_length=20, verbose_name=('Nome do Projeto')) user = models.ForeignKey(User, _on_delete_=models.CASCADE) descricao = HTMLField() How can I make each requirement related to a project that the respective registered user saved and does not show this error message? Thank you very much. -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6A74D796-E98C-48AE-BC06-AB0968189FD9%40hxcore.ol. |
- Filtering combobox according to a project list created by ... Gabriel
- RES: Filtering combobox according to a project list c... Samuel Nogueira

