Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 更改表单模板Django中的提交按钮存在问题_Python_Django_Many To Many_Submit - Fatal编程技术网

Python 更改表单模板Django中的提交按钮存在问题

Python 更改表单模板Django中的提交按钮存在问题,python,django,many-to-many,submit,Python,Django,Many To Many,Submit,我是Django和Python的新手,我仍然不知道如何从许多与字段相关的查找中预填充值,这是我在中的问题 这是我的模型: class Product(models.Model): product_name= models.CharField(max_length=50) price = models.DecimalField(max_digits=10, decimal_places=2, default=Decimal('0.00')) tax_per_item = m

我是Django和Python的新手,我仍然不知道如何从许多与字段相关的查找中预填充值,这是我在中的问题 这是我的模型:

class Product(models.Model):
    product_name= models.CharField(max_length=50)
    price = models.DecimalField(max_digits=10, decimal_places=2, default=Decimal('0.00'))
    tax_per_item = models.DecimalField(max_digits=10, null=True, blank=True, decimal_places=2, default=Decimal('0.00'))
    discount_per_item = models.DecimalField(max_digits=10, null=True, blank=True, decimal_places=2, default=Decimal('0.00'))


class Order(models.Model):
    produks = models.ManyToManyField(Product, verbose_name=u"Kode Produk")
    no_customer = models.ForeignKey(Customer, null=True, blank=True, related_name='%(class)s_kode_cust')

    def order_view(request):
        if 'enter' in request.POST:
            #response to tabular.html template
            return HttpResponseRedirect('/admin/POS/Pemesanan/inline')

class Foo(models.Model):
    product = models.ForeignKey(Product, editable=False)
    pemesanan = models.ForeignKey(Order)
    quantity = models.IntegerField()
    price = models.IntegerField()
    discount = models.IntegerField()
    tax = models.IntegerField()
这是我的管理员:

class PemesananAdmin(admin.ModelAdmin):
fieldsets = (
    ('Customer in Time (Person)', {
        'fields': ('no_customer',),
    }),
    ('Date', {
        'fields' : ('date', 'delivery_date',),
    }),
    ('Order Details', {
        'fields' : ('produks',),
    }),
)
search_fields = ['produks', 'no_customer']
raw_id_fields = ('produks', 'no_customer',)
related_lookup_fields = {
'fk': ['no_customer'],
'm2m': ['produks'],
}
inlines = [
    FooInline,
]

class FooInline(admin.TabularInline):
model = Foo
template = 'admin/POS/Pemesanan/inline/tabular.html'
extra = 0
allow_add = True
这是我的更改表单覆盖模板:

{% extends "admin/change_form.html" %}
{% block after_field_sets %}{{ block.super }}

<form action="" method="post">
<input type="submit" name="enter" value="Enter" />
</form>
{% endblock %}
但是,仍然没有人能告诉我怎么做。如果你能回答我在那页上的问题。现在,我对两个问题感到困惑: 1.我希望我在change_form中的submit按钮也重定向到change_form a.k.a在同一页面中无需刷新页面不更改_列表页面或实际提交。 2.如何从submit按钮获取相关查找“produks”字段集manytomany的实例,以便访问父值类Product并将所有内容预填充到TablerLine类Foo或中间类

仅供参考,提交按钮位于所有字段集下方


谁能帮帮我。感谢您的友好回复:。

您的问题是,这

<form action="" method="post">
<input type="submit" name="enter" value="Enter" />
</form>
只需将“提交”按钮发送回服务器。 表单标记需要对每个表单元素进行排序

只需删除:和
而且它可能会工作。

据我所知,您是否希望显示订单及其项目Foo

我天真的解决方案是:

class Product(models.Model):
   ...

class Order(models.Model):
   products = models.ManyToManyField(Product, through='Item')

class Item(models.Model):
   order = models.ForeignKey(Order)
   product = models.ForeignKey(Product)
   quantity = models.IntegerField()
   ...
管理员可以这么简单:

class ItemInline(admin.TabularInline):
    model = Item

class OrderAdmin(admin.ModelAdmin):
    inlines = (ItemInline,)

你需要测试一下,因为我实际上不能

哦,我明白了,我已经把它去掉了。但现在我的问题是,如何从字段集Kode-Produk-Produk-manytomany字段获取实例,然后将它们传递给我的中间模型Foo?对不起,如果我问得太多了,谢谢:。这就是stackoverflow的全部内容:我在这里回答你的问题:“admin/POS/Pemesanan/inline/tabular.html”是否扩展了“admin/edit_inline/tabular.html”?哦,是的,我想扩展“admin/edit_inline/tabular.html”,这样我可以在单击“回车”按钮后预填充到tabularinline中的字段,与我之前的问题相同:D。。但是现在,我仍然不知道怎么做。我以前搜索过,一篇文章说我必须使用javascript。不过,我还是个新手;。你知道怎么做吗?谢谢:D.不,不是那样的:D.但我想在我之前发布的问题中的UI中显示通过字段集Kode Produk中的相关查找获得的产品的所有值:D.以更改表单类顺序内联项目。对不起,如果我的问题对你来说不清楚;非常感谢你:。