Example #1
0
    def save(self, commit=True, update=False,item_id=None):
        session = Session()
        
        if update:
            item = session.query(Item).get(item_id)
        else:
            item = Item()

        item.title = self.cleaned_data['title']        
        
        if not update:
            session.add(item)
        session.commit()        
        item.id = item.id
        #新建一个item 自动新建一个关系 和一个组合
        item_relation = ItemRelation(title = item.title)
        session.add(item_relation)
        session.commit()       

        item_relation.id = item_relation.id
        item_relation_combination = ItemRelationCombination(item_id =item.id,                                                                      
                                                            item_relation_id = item_relation.id,
                                                            combination_number = 1,
                                                            show_order = 1,
                                                            )
        session.add(item_relation_combination)
        session.commit()
        session.close()
        
        return item
Example #2
0
    def save(self, commit=True, update=False,item_relation_id=None):
        session = Session()
        
        if update:
            item_relation = session.query(ItemRelation).get(item_relation_id)
        else:
            item_relation = ItemRelation()

        item_relation.title = self.cleaned_data['title']        
        
        if not update:
            session.add(item_relation)
        session.commit()        
        item_relation.id = item_relation.id
        session.close()
        
        return item_relation