首页 > 其他 > 详细

Django ManytoMany ,ForeignKey

时间:2016-05-16 10:43:35      阅读:215      评论:0      收藏:0      [点我收藏+]
class Promotion(models.Model):
    shop = models.ForeignKey(User, limit_choices_to=is_shop)
   
    
class Brand(models.Model):
    id = models.PositiveIntegerField(primary_key=True)
    
    watches = models.ManyToManyField(User, blank=True,
                                     limit_choices_to=is_client,
                                     related_name="brand_watches")
    shops = models.ManyToManyField(User, blank=True,
                                   limit_choices_to=is_shop,
                                   related_name="brands_for_shop")
   

查询方法一般有:

 #查询出含有brand——id 的所有用户
queryset_user = User.objects.filter(brands_for_shop__id=obj.id).values_list("id")
demo=Promotion.objects.filter(shop__id=i).values_list("rebate_to_client")

 

Django ManytoMany ,ForeignKey

原文:http://www.cnblogs.com/linbinqiang/p/5497089.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!