Filtering combobox according to a project list created by logged user

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Filtering combobox according to a project list created by logged user

Gabriel-3
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5824d6a7-0419-4fa1-a0f6-abe1789675e4n%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

RES: Filtering combobox according to a project list created by logged user

Samuel Nogueira

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: [hidden email]
Enviado:domingo, 25 de outubro de 2020 21:45
Para: [hidden email]
Assunto: 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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5824d6a7-0419-4fa1-a0f6-abe1789675e4n%40googlegroups.com.

 

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6A74D796-E98C-48AE-BC06-AB0968189FD9%40hxcore.ol.