python - How to send data set to multiple rows in same table using save method (in Django 1.8 / SQLLIte )? -
i code project using django 1.8. model class.
# encoding: utf-8 django.contrib.auth.models import user django.db import models django.utils.encoding import python_2_unicode_compatible django.utils.timezone import .algo import algo django.http import httpresponse @python_2_unicode_compatible class key_gen(models.model): key_beging_code =models.decimalfield('brand_name +pack_size' ,max_digits=5, decimal_places=2) key_quantity =models.decimalfield("key quantity" ,max_digits=19, decimal_places=10) key_code =models.charfield('key code' ,max_length=50 , unique=true) is_public = models.booleanfield('public', default=true) date_created = models.datetimefield('date created',auto_now_add=true) date_updated = models.datetimefield('date updated',auto_now_add=true) class meta: verbose_name='key_gen' verbose_name_plural='keys_gen' ordering = ['-date_created'] def __str__(self): return '%s' % (self.key_code) def get_key_code(self,x,y): alist = [] x = algo(int(x),int(y),alist) keys =x.id_generator() return keys def save(self, *args, **kwargs): if not self.key_code: self.key_code_temp =self.get_key_code(self.key_beging_code,self.key_quantity) self.key_code_temp =self.get_key_code(self.key_beging_code,self.key_quantity) i=0; x in self.key_code_temp: +=1; self.key_code = self.key_code_temp[i-1] super(key_gen, self).save(*args, **kwargs)
i call algo function , return data list function.
self.key_code_tempt=self.get_key_code(self.key_beging_code,self.key_quantity) #eg . ['001r','ou3r', '4002']
i want send data 1 one database table.but current send 1 value database.
i put loop iterate list , call '.save' method repeatedly.but doesn’t show call repeatedly. new comer python web programming , hope expert help.i notice key list pass , loop inside save method run once.
============view class code==================================
@login_required def key_create(request): if request.method == 'post': form = keygenarateform(data=request.post) if form.is_valid(): request.post._mutable = true key_gen = form.save(commit=false) key_gen.save() return redirect('marcador_bookmark_user',username=request.user.username) else: form = keygenarateform() context = {'form': form, 'create_key': true} return render(request, 'marcador/key_genarate_form.html', context)
this sqllite db table. think , can more idea see image.
Comments
Post a Comment