I need help with Python code

copy_groups = Group()
groups = Group.query.filter(Group.project_id == curent_project_id)
for i in groups:
    copy_groups.project_id = curent_project.id
    copy_groups.name = i.name
    db.session.add(copy_groups)
db.session.commit()

When I used this code it was added only last group, but I need add all group in groups.

When I used

copy_groups = Group()
groups = Group.query.filter(Group.project_id == curent_project_id)
for i in groups:
    copy_groups.project_id = curent_project.id
    copy_groups.name = i.name
    db.session.add(copy_groups)
    db.session.commit()

I had error.

But I need add all group in groups

Please help me with this problem. Thank you.

share|improve this question
    
create copy_groups = Group() inside for loop – furas 45 mins ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.