def create_update_myindex(self): if self.payer_ids: user_ids = self.payer_ids+','+self.consumer_ids else: user_ids = self.consumer_ids user_ids = [ int(x) for x in user_ids.split(',') ] if self.payer_names: user_names = self.payer_names+','+self.consumer_names else: user_names = self.consumer_names user_names = user_names.split(',') user_data = [] existed_ids = set([]) for i in range(len(user_ids)): user_id,user_name = user_ids[i],user_names[i] if user_id not in existed_ids: existed_ids.add(user_id) user_data.append( [user_id,user_name] ) for user_id,user_name in user_data: try: mi = MyIndex.objects.get(user_id=user_id) mi.expense_ids = insert_names(mi.expense_ids,str(self.expense_id)) except MyIndex.DoesNotExist: mi = MyIndex() mi.user_id = user_id mi.user_name = user_name mi.expense_ids = str(self.expense_id) mi.save() print mi.user_name,mi.expense_ids
def create_update_tag(self): for tag_name in self.tags.split(','): try: ta = Tag.objects.get(tag_name=tag_name) ta.expense_ids = insert_names(ta.expense_ids,str(self.expense_id)) except Tag.DoesNotExist: ta = Tag() ta.total = 0 ta.tag_name = tag_name ta.expense_ids = str(self.expense_id) ta.total += float(self.amount) ta.save()