1.正向查询
obj = models.User.objects.get(name='longge')
name = obj.group.name
print(name) # 肖邦组
2.反向查询
"""
反向查询
"""
obj = models.Group.objects.get(name='龟叔组')
user_obj = obj.user_set.first() # 关联表_set
name = user_obj.name
print(name) # Maxs_hu
3.get和filter的区别
models.User.objects.get(name='longge') # User object
models.User.objects.filter(name='longge') # querySet对象 加上.first()就和上面get是一样的效果
标签:obj,name,get,models,Django,反向,User,查询
From: https://www.cnblogs.com/Maxs-message/p/17213423.html