有2 forms一个页面上。
有2种型号:1 Product.. 2. SpeciallyPrice. SpeciallyPrice通过FK链接到Product. 同时,SpeciallyPrice是Inline 模型中的Product.
的字段SpecialPriceForm是使用JS自动创建的。也就是说,它们可能是第n个数字。有必要为每个创建的字段创建一个记录。原则上,我猜怎么做 - 使用循环来驱动获得的值。但问题是由于某种原因None来自form. 请帮我。
模板+js
<html><body>
Special price from {{ special_form.adittional_specially_price }} kg {{ special_form.adittional_specially_number }} usd
<script>
(function(){
var copy = document.querySelector('.field.inline.specially').cloneNode(true);
document.querySelector('html').addEventListener('input', function(e){
if(e.target.classList.contains('event') && e.target.tagName == 'INPUT'){
var error = 0;
for(var evt of document.querySelectorAll('.field.inline.specially input.event')){
evt.value = evt.value.replace(/[^\d]/,'');
if(!evt.value || +evt.value < 1) error++;
}
if(!error){
var last = document.querySelectorAll('.field.inline.specially');
last[last.length-1].insertAdjacentHTML('afterEnd', copy.outerHTML);
}
}
});
})();
</script>
</body></html>
这个表格我在视图中看到,当打印form检查时
<label for="specially" class="subhead">Special price from</label>
<span class="id_specially_price"><input type="text" name="adittional_specially_price" style="width: 165px" class="event" id="id_adittional_specially_price"></span>
<span>kg</span>
<span class="id_specially_number"><input type="text" name="adittional_specially_number" style="width: 100px" class="event" id="id_adittional_specially_number"></span>
<span>usd</span>
我查看了视图- 表单在那里呈现,但只有一个字段,而不是所有字段。而形式是空的。如何解决这个问题?也许应该连接Ajax并以某种方式处理请求?或者有更多Django 的选择吗?
鸿蒙传说
相关分类