title: how can I filter the difference between the two models? using django
body: <p>I have 2 models, <strong>Product</strong> and <strong>ProductRelatedGroupAndProduct</strong> , the <strong>Product</strong> have 5 data, [chicken, okra, ampalaya, cabbage] and the <strong>ProductRelatedGroupAndProduct</strong> have [chicken, okra, cabbage] how do i get the remaining data in <strong>Product</strong> that dont have in <strong>ProductRelatedGroupAndProduct</strong> ?</p>
  <p><a href="https://i.stack.imgur.com/CIyVk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CIyVk.png" alt="enter image description here" /></a></p>
  <p><em>the choosen product is <strong>ProductRelatedGroupAndProduct</strong> and the list of product is <strong>Product</strong></em></p>
  <p>I just want that the data displayed on the choosen product should no longer be visible in the product list.</p>
  <p>so far this is my views.py</p>
  <pre><code>def searchrelatedproduct(request):
      id = request.GET.get('relatedproductID')
      products = Product.objects.all()
      relatedproduct = ProductRelatedGroupAndProduct.objects.filter(productrelatedgroup = id)
      return render(request, &quot;customAdmin/relatedproduct.html&quot;,{&quot;products&quot;:products,&quot;relatedproduct&quot;:relatedproduct})
  </code></pre>
  <p>this is my html</p>
  <pre><code>&lt;div class=&quot;container&quot;&gt;
      &lt;form method=&quot;POST&quot; action=&quot;/GroupOfProduct/&quot; enctype=&quot;multipart/form-data&quot;&gt;{% csrf_token %}
    &lt;h2&gt;Product &lt;/h2&gt;
      &lt;div class=&quot;form-group&quot;&gt;
        &lt;br&gt;
        &lt;label for=&quot;sel2&quot;&gt;List Of Products&lt;/label&gt;
              &lt;select multiple class=&quot;form-control&quot; id=&quot;sel2&quot; name=&quot;product&quot;&gt;
                  {% for product in products %}
                      &lt;option&gt;{{product.product}}&lt;/option&gt;
                  {% endfor %}
              &lt;/select&gt;
      &lt;/div&gt;
        &lt;input type=&quot;submit&quot; style=&quot;float:right;&quot;&gt;
    &lt;/form&gt;
  &lt;/div&gt;
  
  
  &lt;div class=&quot;container&quot;&gt;
    &lt;h2&gt;Choosen Product&lt;/h2&gt;
    &lt;form method=&quot;POST&quot; action=&quot;/UpdateGroupOfProduct/&quot; enctype=&quot;multipart/form-data&quot;&gt;{% csrf_token %}
        &lt;input type=&quot;submit&quot; style=&quot;float:right;&quot;&gt;
      &lt;div class=&quot;form-group&quot;&gt;
        &lt;br&gt;
        &lt;label for=&quot;sel2&quot;&gt;List Of Choosen Products&lt;/label&gt;
          &lt;select multiple class=&quot;form-control&quot; id=&quot;sel2&quot; name=&quot;relatedproduct&quot;&gt;
            {% for product in relatedproduct %}
  
              &lt;option value=&quot;{{ product.id }}&quot;&gt;{{product.product}}&lt;/option&gt;
            {% endfor %}
          &lt;/select&gt;
      &lt;/div&gt;
  
    &lt;/form&gt;
  &lt;/div&gt;
  </code></pre>
  <p>this is my models.py</p>
  <pre><code>class ProductRelatedGroupAndProduct(models.Model):
      product = models.ForeignKey(Product,on_delete=models.SET_NULL, null=True,blank=True,verbose_name=&quot;Product&quot;)
     productrelatedgroup = models.ForeignKey('ProductGroup',
                              on_delete=models.SET_NULL, null=True, blank=True,
                              verbose_name=&quot;ProductGroup&quot;)
  class Product(models.Model):
      product = models.CharField(max_length=500)
  
  
  class ProductGroup(models.Model):
  
      category = models.CharField(max_length=500, blank=True)
  </code></pre>
  <p>UPDATE</p>
  <p>when i tried this</p>
  <pre><code>diffproducts = products.exclude(pk__in=relatedproduct)
  print(diffproducts)
  </code></pre>
  <p>it prints all data of the Product</p>
  <pre><code>&lt;QuerySet [&lt;Product: cabbage&gt;, &lt;Product: ampalaya&gt;, &lt;Product: okra&gt;, &lt;Product: Chicken&gt;]&gt;
  </code></pre>
  <p>and when i tried this</p>
  <pre><code>unused_product = set(relatedproduct).difference(set(products))
  print(unused_product)
  
  ***result***
  {&lt;ProductRelatedGroupAndProduct: cabbage&gt;, &lt;ProductRelatedGroupAndProduct: ampalaya&gt;, &lt;ProductRelatedGroupAndProduct: okra&gt;}
  </code></pre>
  <p>and this</p>
  <pre><code>Product.objects.filter(productrelatedgroupandproduct__isnull=True)
  </code></pre>
  <p>i get this error</p>
  <pre><code>django.core.exceptions.FieldError: Cannot resolve keyword 'productrelatedgroupandproduct' into field
  </code></pre>