下面我有以下代码,这是我在这里为工作所做的请求的形式的编辑,因为我不得不更改某些视图,我的更新必须是手动的,而select字段不是得到我从数据库带来的结果,除了选择,所有字段都在工作。 as it is now ||| as should be
class EditPedido(View):
def get(self, request, venda):
data = {}
venda = fixa.objects.get(id=venda)
data['filial'] = venda.regional
return render(request, 'fixa/fixa_update.html', data)
<select name="filial" class="select form-control" required="" id="filial">
<option value="" selected="">---------</option>
{% for filial in filiais %}
<option value="{{ filial.id }}">{{ filial.nome }}</option>
{% endfor %}
</select>
编辑
class EditPedido(View):
def get(self, request, venda):
empresa_logada = request.user.funcionario.empresa
data = {}
data['filiais'] = empresa.objects.filter(nome=empresa_logada)
venda = fixa.objects.get(id=venda)
data['filial'] = venda.regional
return render(request, 'fixa/fixa_update.html', data)
<select name="filial" class="select form-control" required="" id="filial">
<option value="" selected="">---------</option>
{% for filial in filiais %}
<option value="{{ filial.id }}">{{ filial.nome }}</option>
{% endfor %}
</select>
<form method="POST" action="{% url 'create_fixa' %}">
{% csrf_token %}
<h2>number do Pedido: {{ sell.number }}</h2>
<p><font color="RED">{{MSG}}</font></p>
<hr>
<br>
<div class="form-row">
<div class="form-group col-md-3 mb-0">
<label for="number">Nº da Simulação</label>
<input type="text" name="number" class="form-control" value="{{number}}" required="">
</div>
<div class="form-group col-md-9 mb-0">
<label for="razao">Razão Social</label>
<input type="text" name="razao" class="form-control" value="{{razao}}" required="">
</div>
</div>
<br>
<div class="form-row">
<div class="form-group col-md-6 mb-0">
<label for="razao">CNPJ</label>
<input type="text" name="cnpj" class="form-control" data-mask="00.000.000/0000-00" value="{{cnpj}}" required="">
</div>
<div class="form-group col-md-6 mb-0">
<label for="tipo">TIPO</label>
<select name="tp_cli" class="select form-control" required="" id="tp_cli">
<option value="" selected="">---------</option>
<option value="FRESH">FRESH</option>
<option value="BASE">BASE</option>
</select>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-6 mb-0">
<label for="razao">Filial</label>
<select name="filial" class="select form-control" required="" id="id_regional">
{% for filial in filiais %}
<option value="{{filial.id }}">{{ filial.nome }} {% if filial.id == filial %}selected{% endif %}</option>
{% endfor %}
</select>
</div>
<div class="form-group col-md-6 mb-0">
<label for="tipo">Indicação</label>
<select name="indicacao" class="select form-control" id="indicacao">
<option value="" selected="">---------</option>
{% for indicacao in indicaoes %}
<option value="{{ indicacao.id }}">{{ indicacao.nm_primeiro_nome }} {{indicacao.nm_segundo_nome}}</option>
{% endfor %}
</select>
</div>
<div class="form-group col-md-6 mb-0">
<label for="tipo">Status</label>
<select name="status" class="select form-control" id="status">
<option value="" selected="">---------</option>
{% for statu in status %}
<option value="{{ statu.id }}">{{ statu.nome_st }}</option>
{% endfor %}
</select>
</div>
</div>
<br>
<input type="hidden" value="{{sell.id}}" name="sell_id">
<button type="submit" class="btn btn-success">Salvar</button>
</form>
class EditOrder(View):
def get(self, request, sell, *args, **kwargs):
company_entered = request.user.employee.company
parent_company = request.user.employee.company.company_pai
data = {}
data['status'] = tb_status.objects.all()
sell = fixa.objects.get(id=sell)
if parent_company:
data['filiais'] = company.objects.filter(nome=company_entered)
data['indicaoes'] = employee.objects.filter(cargo__nome='Vendedor', company__nome=company_entered)
else:
data['filiais'] = company.objects.filter(nome=company_entered) | company.objects.filter(
company_pai=company_entered)
data['indicaoes'] = employee.objects.filter(cargo__nome='Vendedor')
data['number'] = sell.number
data['razao'] = sell.nm_razao
data['cnpj'] = sell.nr_cnpj
data['tp_cli'] = sell.tipo_cli
data['filia'] = sell.regional_id
data['indicacao'] = sell.indicacao
data['sell'] = sell
data['family'] = tb_tp_prod.objects.all()
data['type'] = tb_tipo_servico.objects.all()
data['qtds'] = tb_qtd.objects.all()
data['itens'] = sell.itemdopedido_set.all()
return render(request, 'fixa/fixa_update.html', data)
答案 0 :(得分:0)
这就是您上一次评论的内容(我不知道第三和第四选项中的单词之前的空格来自何处,但也许您应该删除它们)
<select name="filial" class="select form-control" required="" id="filial">
<option value="" selected="">--------</option>
<option value="1">TESTE</option>
<option value="2"> SOROCABA</option>
<option value="5"> MARILIA</option>
</select>
您已选择第一个选项,即--------。我想你想要这个
<select name="filial" class="select form-control" required="" id="filial">
<option value="1">TESTE</option>
<option value="2"> SOROCABA</option>
<option value="5" selected=""> MARILIA</option>
</select>
您将必须向模板指示要选择哪个选项,您可以将其作为变量传递给类似
data['selection'] = 5
然后在模板中
<option value="{{ filial.id }}" {% if filial.id == selection %}selected=""{% endif %}>{{ filial.nome }}</option>
我不确定{%if filial.id == selected%}语句的语法。我使用的不是很多,但想法是将标签放在需要它的选项中。