python - Django ManyToMany Relation "Contains" Statement -
I am creating a small task manager, all the labels of the job are that I must select all the tasks in which some labels At the moment, I am:
  task = tasks.obages.Al (). Filter (label_in = label_list) .distink ()    Returns all the tasks, where at least one label is also in the label_list, but I only need those labels whose labels All label labels are in the list  
 More precise examples: If I pass [['1', '2'] in the form of a label 'list', then I  not  all the tasks Label 1  or  label 2 returned (now it is happening), but label 1  and  are labeled as 2 All work should be returned.   I want to work with label  in  label list   The relation task label is many:  
  class Work (models.Model): .... label = Models.ManyToManyField (label, empty = true, empty = true) ....     
  This is reaching the limits of the OSM of the DNS, but you can try:  
  labels = [ '1', '2'] qs = Task.objects.all (): qs = qs.filter (label = label). Distinct ()    Obviously, very ugly, and it will be a very expensive operation for a long list of labels, but it can work to get you by.  
 Alternatively, you can see a mature designer tagging app that provides similar 'labeled' functionality that they handle 'included' problems by using raw SQL.   
 
  
Comments
Post a Comment