django submit和ajax,Django form ajax submit concurrently

I have some field created by Django form and there are some other data I want to post to other form using jQuery(Ajax).

Is there any way to post them to different tables with two different ways at the same time?

form.py

class MyForm(forms.ModelForm):

class Meta:

model = models.Planning

fields = ['title','description','open','owner','upload_time']

template

{% csrf_token %}

{{ form.management_form }}

country

please choose

{% for x in areas %}

{{x.area_country}}

{% endfor %}

title:{{form.title}}

description:{{form.description}}

submit

I want to store the chosen areas and foreign key to another table with ajax

view

def make_list(request):

template = get_template('index.html')

areas = models.Area.objects.values('area_country').distinct()

max_my_id = models.RoutePlanning.objects.all().aggregate(Max('my_id'))

my_id = int(max_my_id['my_id__max']) + 1

#city = request.POST.get('my_areas')

if request.method == 'POST':

form = forms.MyForm(request.POST,initial={'owner':username,'route_id':my_id,'route_upload_time':datetime.now()})

if form.is_valid():

form.save()

return HttpResponseRedirect('/make_player')

else:

loi_form = forms.MyForm(initial={'owner':username,'route_id':my_id,'route_upload_time':datetime.now()})

request_context = RequestContext(request)

request_context.push(locals())

html = template.render(request_context)

return HttpResponse(html)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值