Sunday, October 25, 2020

Filtering combobox according to a project list created by logged user

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 django-users+unsubscribe@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.

No comments:

Post a Comment