def perform_create(self, serializer): prestr = 'en' lastno = EnWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr + '000000' else: maxno = lastno['fwordno__max'] serializer.save(fwordno=makecode(maxno, prestr, 8), fuser='******')
def perform_create(self, serializer): prestr = 'ja' lastno = JaWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr + '000000' else: maxno = lastno['fwordno__max'] serializer.save(fwordno=makecode(maxno, prestr, 8), fuser=self.request.user.first_name)
def form_valid(self, form): prestr = 'cn' lastno = CnWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr + '000000' else: maxno = lastno['fwordno__max'] wordno = makecode(maxno, prestr, 8) form.instance.fwordno = wordno return super().form_valid(form)
def form_valid(self, form): prestr = 'en' lastno = EnWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr+'000000' else: maxno = lastno['fwordno__max'] wordno = makecode(maxno,prestr,8) form.instance.fwordno = wordno if 'savenext' in form.data.keys(): self.success_url = reverse_lazy('enword-add') return super().form_valid(form)
def funaddword(wtype, pusername, worddict): prestr = wtype statu = 'Success' wordobj = None errinfo = '' # 增加日语单词 if wtype == 'ja': lastno = JaWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr + '000000' else: maxno = lastno['fwordno__max'] wordno = makecode(maxno, prestr, 8) wordobj = JaWord() wordobj.fwordno = wordno wordobj.fword = worddict['word'] wordobj.fpronunciation = worddict['pronunciation'] #wordobj.fwordclass = wordobj.fuser = pusername try: wordobj.save() except: statu = 'Fail' errinfo = "新增失败,请检查!" #return render(request,'inbill/billerror.html',{"errinfo":errinfo}) # 增加中文单词 if wtype == 'cn': lastno = CnWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr + '000000' else: maxno = lastno['fwordno__max'] wordno = makecode(maxno, prestr, 8) wordobj = CnWord() wordobj.fwordno = wordno wordobj.fword = worddict['word'] wordobj.fpronunciation = worddict['pronunciation'] try: wordobj.save() except: statu = 'Fail' errinfo = "新增失败,请检查!" #return render(request,'inbill/billerror.html',{"errinfo":errinfo}) if wtype == 'en': lastno = EnWord.objects.filter().aggregate(Max('fwordno')) if not lastno['fwordno__max']: maxno = prestr + '000000' else: maxno = lastno['fwordno__max'] wordno = makecode(maxno, prestr, 8) wordobj = EnWord() wordobj.fwordno = wordno wordobj.fword = worddict['word'] wordobj.fpronunciation = worddict['pronunciation'] try: wordobj.save() except: statu = 'Fail' errinfo = "新增失败,请检查!" #return render(request,'inbill/billerror.html',{"errinfo":errinfo}) return {"statu": statu, "wordobj": wordobj, "info": errinfo}