Django ManytoMany ,ForeignKey

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")

 

posted @ 2016-05-16 09:55  gopher-lin  阅读(200)  评论(0编辑  收藏  举报