How to get the complement in django?

51 views
Skip to first unread message

田福顿

unread,
Apr 29, 2015, 6:11:51 AM4/29/15
to django...@googlegroups.com
I want to connect to tables than get their complment, but I don't know how to do it? Plaea give me some suggestion. I have wasted two days in this problem.BTW this way didn't work:Django: Getting complement of queryset

Tom Evans

unread,
Apr 29, 2015, 6:32:09 AM4/29/15
to django...@googlegroups.com
That is how to do it. What doesn't work? Show an example..

Tom

田福顿

unread,
Apr 29, 2015, 7:11:40 AM4/29/15
to django...@googlegroups.com


在 2015年4月29日星期三 UTC+8下午6:32:09,Tom Evans写道:
this is my code 
if StudyRecord.objects.filter(id = i_d ).exists():
            current=StudyRecord.objects.get(id = i_d )
            if PersonalRecord.objects.filter(book = current.book,user_id = current.id).exists():
                p_r = PersonalRecord.objects.filter(book = current.book,id = i_d)
                for iterm in p_r:
                words = WordBase.objects.filter(belong = current.book)
                new_words=WordBase.objects.filter(belong = current.book).exclude(number__in=p_r.values_list('number', flat=True))[:1]
                for single_words in new_words:                 
                    u1 = PersonalRecord(user_id = request.user.id,begtime= time.time(),
                                                endtime="",lasttime="",times = 0, status = 0,
                                                number = single_words.number,book = single_words.belong,
                                              ) 
                    u1.save()
            else:
                new_words = WordBase.objects.filter(belong = current.book )[:5]
                return HttpResponse("fail")
                for single_words in new_words:              
                    u1 = PersonalRecord(user_id = request.user.id,begtime= time.time(),
                                        endtime="",lasttime="",times = 1, status = 0,
                                        number = single_words.number,book = single_words.belong,)                                               
                    u1.save()
            
but, it didn't work, it still save the record that the database already have
 
Reply all
Reply to author
Forward
0 new messages