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']
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/
-----------------------------------------------------------------------------------------------------
--
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 django-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5824d6a7-0419-4fa1-a0f6-abe1789675e4n%40googlegroups.com.