Criei um model que possui um campo choice que vem de outro model (Company), mas quando faço um for para retornar os campos que existem cadastrados no banco, o campo aparece vazio no formulário.
<div class="col-md-6">
<label><b>Empresa</b></label>
<select class="form-control form-control-md" name="company">
{% for company in companys %}
<option>{{company.name_company}}</option>
</select>
{% endfor %}
</div>
from django.db import models from datetime import datetime from company.models import Company
class Tool(models.Model): name = models.CharField(max_length=100) tag_tool = models.CharField(max_length=30)
type_tool_choices = {
('Manual', 'Manual'),
('Eletroportátil', 'Eletroportátil'),
}
type = models.CharField(max_length=50, choices=type_tool_choices)
area = models.CharField(max_length=50)
date_register = models.DateTimeField(default=datetime.now, blank=True)
status_choices = {
('Ativo', 'Ativo'),
('Inativo', 'Inativo'),
('Condenada', 'Condenada')
}
status = models.CharField(max_length=50, choices=status_choices)
tag_image = models.ImageField(upload_to='fotos/%d/%m/%Y/', blank=True)
tool_image = models.ImageField(upload_to='fotos/%d/%m/%Y/', blank=True)
observation = models.TextField(max_length=500)
company = models.ForeignKey(Company, on_delete=models.CASCADE)
def __str__(self):
return self.name
def __str__(self):
return self.tag_tool