{"action":"created","issue":{"url":"https://api.github.com/repos/Deft-pawN/sam-for-test/issues/16","repository_url":"https://api.github.com/repos/Deft-pawN/sam-for-test","labels_url":"https://api.github.com/repos/Deft-pawN/sam-for-test/issues/16/labels{/name}","comments_url":"https://api.github.com/repos/Deft-pawN/sam-for-test/issues/16/comments","events_url":"https://api.github.com/repos/Deft-pawN/sam-for-test/issues/16/events","html_url":"https://github.com/Deft-pawN/sam-for-test/issues/16","id":275697732,"number":16,"title":"Some Experiences Filter In the Django ","user":{"login":"Deft-pawN","id":25686881,"avatar_url":"https://avatars3.githubusercontent.com/u/25686881?v=4","gravatar_id":"","url":"https://api.github.com/users/Deft-pawN","html_url":"https://github.com/Deft-pawN","followers_url":"https://api.github.com/users/Deft-pawN/followers","following_url":"https://api.github.com/users/Deft-pawN/following{/other_user}","gists_url":"https://api.github.com/users/Deft-pawN/gists{/gist_id}","starred_url":"https://api.github.com/users/Deft-pawN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Deft-pawN/subscriptions","organizations_url":"https://api.github.com/users/Deft-pawN/orgs","repos_url":"https://api.github.com/users/Deft-pawN/repos","events_url":"https://api.github.com/users/Deft-pawN/events{/privacy}","received_events_url":"https://api.github.com/users/Deft-pawN/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2017-11-21T12:40:35Z","updated_at":"2017-11-28T07:13:43Z","closed_at":null,"author_association":"OWNER","body":"filter\r\n1.按照某一列进行合并排序,统计格式并且按照取前N个值,values 相当于sql 中的groupby：\r\nbroker_ranked_list_1 = Brand.objects.all().values('Primary_Broker').annotate(total=Count('Primary_Broker')).order_by('-total')[:10]\r\n查询数据库效率的aggregate(聚合函数)和annotate函数：\r\n2.1 aggregate来进行计数：查询某个 有多少个B 对象使用 A对象 作为外键 B_Num = B.objects.aggregate(num_A=Count('A'))\r\n2.2 aggregate来进行求和,平均min,max值 ：查询某个 有多少个B 对象使用 A对象 作为外键 B_Num = B.objects.aggregate(num_A=Count('A'))/max('A')/min('A')\r\n2.3 使用value_list 函数使用 解释 把 :msgS = A.objects.values_list('A.columnB')取得A 对象的 B 属性的所有的值，并且用list的方式返还回来,这边返回的list 通常会有L 这个符号 ,需要执行下面这一步骤： brand_group_ids = [int(item) for item in brand_group_ids]\r\n2.4 使用annotate进行分类,表示通过id 进行分类 把 :msgS = A.objects.values_list('A.columnB').annotate(msg_num=Count(‘id’)), 根据id 把对应的column B的值进行分类，annotate 作用就是相当于group by 的形式\r\n2.5 使用.order_by('-total')[:10]函数取得前十/最后十个的数据:broker_ranked_list_1 = Brand.objects.all().values('Primary_Broker').annotate(total=Count('Primary_Broker')).order_by('-total')[:10]最后十个使用的是'-'符号\r\n3. 反向寻找ManyToMany模型的对应的Object,使用的**_set:`company_instance.brand_set.add/delete/`"},"comment":{"url":"https://api.github.com/repos/Deft-pawN/sam-for-test/issues/comments/347434192","html_url":"https://github.com/Deft-pawN/sam-for-test/issues/16#issuecomment-347434192","issue_url":"https://api.github.com/repos/Deft-pawN/sam-for-test/issues/16","id":347434192,"user":{"login":"Deft-pawN","id":25686881,"avatar_url":"https://avatars3.githubusercontent.com/u/25686881?v=4","gravatar_id":"","url":"https://api.github.com/users/Deft-pawN","html_url":"https://github.com/Deft-pawN","followers_url":"https://api.github.com/users/Deft-pawN/followers","following_url":"https://api.github.com/users/Deft-pawN/following{/other_user}","gists_url":"https://api.github.com/users/Deft-pawN/gists{/gist_id}","starred_url":"https://api.github.com/users/Deft-pawN/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Deft-pawN/subscriptions","organizations_url":"https://api.github.com/users/Deft-pawN/orgs","repos_url":"https://api.github.com/users/Deft-pawN/repos","events_url":"https://api.github.com/users/Deft-pawN/events{/privacy}","received_events_url":"https://api.github.com/users/Deft-pawN/received_events","type":"User","site_admin":false},"created_at":"2017-11-28T07:13:43Z","updated_at":"2017-11-28T07:13:43Z","author_association":"OWNER","body":"删除对应的外键操作 : Brand_Group_instance.brand_set.all().delete() ,brand_group 是  brand 的外键"}}
{"actor":{"display_login":"Deft-pawN"}}