开发者

Cleaner way to save foreign key relationship in django

开发者 https://www.devze.com 2023-03-09 10:38 出处:网络
I am currently doing the following and was wondering if there\'s any way to condense these 4 lines...as they\'r开发者_开发技巧e very verbose....

I am currently doing the following and was wondering if there's any way to condense these 4 lines...as they'r开发者_开发技巧e very verbose....

g = game_form.save(commit=False)
team = Team.objects.get(pk=team_id)
g.team = team
g.save()


If it's ok for Team to be part of the form then I would make Team a ModelChoiceField in my form. Django will handle everything behind the scenes for you.

0

精彩评论

暂无评论...
验证码 换一张
取 消