0
Basically the user enters the company profile and makes a comment and a rating. I need the company ID to be passed on this form and I get the ID or User Name I have a system that uses USER extended for User and Business. And I created a Comment table, which imports the User Id from the Trade table and the Name of the user table. But I’m not being able to view the company id or the name of the user who is commenting. Remembering that only registered users can comment
py.models
class Negocio(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
empresa = models.CharField(max_length=50, blank=False)
class Usuario(models.Model):
nome = models.CharField(max_length=50, blank=False)
sobrenome = models.CharField(max_length=50, blank=False)
class Comentario(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
nome = models.ForeignKey(Usuario, on_delete=models.CASCADE)
comentario = models.CharField(max_length=255, blank=True)
nota = models.CharField(max_length=255, choices=NOTA_CHOICES, blank=True)
py views.
def comentario_form(request):
comentario = Comentario.objects.all()
form = ComentarioForm()
data = {'comentario': comentario, 'form': form}
return render(request, 'profile_negocio/comentario.html', data)
def cadastro_comentario(request):
if request.method == 'POST':
form = ComentarioForm(request.POST)
if form.is_valid():
user = form.save()
form.instance.user = request.user
form.instance.nome = request.user
user.usuario.nome = form.cleaned_data.get('comentario')
user.usuario.sobrenome = form.cleaned_data.get('nota')
user.save()
return redirect('sistema_perfil')
else:
form = UsuarioForm()
return render(request, 'profile_negocio/comentario.html', {'form': form})
html commentary.
<form method="post" action="{% url 'cadastro_comentario' %}"
class="form-signin" enctype="multipart/form-data" id="form" name="form" validate>
{% csrf_token %}
<div class="form-row ">
<div class="form-group col-md-6 text-center">
{{ form.comentario| as_crispy_field}}
<div class="form-group col-md-6 text-center">
{{ form.nota| as_crispy_field}}
</div>
</div>
</div>
<input type="submit" class="btn btn-primary ">
profile html.
{% for comentario in comentarios %}
<div class="row">
<div class="col-md-12">
{{ comentario.nome }} - Nota: {{ comentario.nota }}
</div>
<div class="col-md-12">
{{ comentario.comentario }}
</div>
</div>
{% endfor %}
I don’t understand what the question is, some problem in some part of the code? In what part of the code you need help?
– Sidon
In the view, I need you to automatically pass the id of the Business, which is the page where the user will comment and pass tbm the name of the user who is commenting
– Mauricio Kalfelz
I’ll work on my graduation to make it clearer.
– Sidon