开发者

Cleaner way to save foreign key relationship in django

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜