title: How to display data from Django manager's method?
body: <p>I'm trying to display a dropdown list to show all the available batches with their 'expiration status' and 'quantity availability status' and 'activation status'.</p>
  <p>What I did so far is that I have created a QuerySet and Manager classes in my Django model class, and I want to retrieve these classes and display them in my template. But the problem is that it didn't work, in my templates it displays nothing, and the select field doesn't show any choices.</p>
  <p>Here's what I did in <strong>models.py</strong>:</p>
  <pre><code>class ExpirationStatus(models.TextChoices):
  
      VALID='VALID',_('Valid')
      ONE_MONTH= 'ONE_MONTH',_('One month or Less')
      THREE_MONTHS='THREE_MONTHS',_('Three Months Or Less')
      EXPIRED='EXPIRED',_('Expired')
      
      
  class BatchQuerySet(models.QuerySet):
  
      def annotate_expiration_status(self):
          one_month=date.today() - timedelta(days=30)
          three_months=date.today() - timedelta(days=90)
          today=date.today()
          
          return self.annotate(expiration_status= Case(
              When(expiry_date__lt=today,then=Value(ExpirationStatus.EXPIRED)),
              When(expiry_date__lte=one_month,then=Value(ExpirationStatus.ONE_MONTH)),
              When(expiry_date__lte=three_months, then=Value(ExpirationStatus.THREE_MONTHS)),
               When(expiry_date__gt=three_months, then=Value(ExpirationStatus.VALID)),
             )).order_by('arrival_date')
  
  class BatchManager(models.Manager):
  
      use_for_related_fields = True
      def annotate_expiration_status(self):
          return self.get_queryset().annotate_expiration_status()
  
      def get_queryset(self):
          return BatchQuerySet(model=self.model, using=self._db)
  
  
  class Batch(models.Model):
  
      class Status(models.TextChoices):
          ACTIVE = 'active', _('Active')
          INACTIVE = 'inactive', _('Inactive')
      
      product = models.ForeignKey(Product, on_delete=models.PROTECT, related_name='product_batch')
      expiry_date = models.DateField()
      quantity_bought = models.PositiveIntegerField() 
      status=models.CharField(max_length=32, null=True, choices=Status.choices)                       
      arrival_date = models.DateField(auto_now_add=False)  
  
      objects=BatchManager()
  
      def available_quantity(self):
          return self.quantity_bought-(self.issued_batches.aggregate(total_issued_quantity=Sum('issued_quantity')).get('total_issued_quantity') or 0)
  
      def __str__(self):
          return self.product.name + ' \'s batch '
  </code></pre>
  <p>Here's what I did in <strong>views.py</strong>:</p>
  <pre><code>class BatchChange (ListView):
      model = Batch
      template_name ='shop/batches_modal.html'
      context_object_name = 'batches'
  
      def get_queryset(self):
  
          product=Product.objects.get(received_product__id=self.kwargs.get('selected_product_id'))
          
          queryset= super().get_queryset()
  
          queryset=queryset.filter(product_id=product.id)
  
          return queryset
  </code></pre>
  <p>Here's what I did in <strong>batches_modal.html</strong>:</p>
  <pre><code>&lt;form method=&quot;POST&quot; action=&quot;{% url 'pharmacy:batches_modal' selected_product.id %}&quot;&gt;
              {% csrf_token %}
              &lt;div class=&quot;modal-body&quot;&gt;
                 {% if batches %}
                  &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label for=&quot;batch&quot; class=&quot;col-form-label&quot;&gt;Batch Number:&lt;/label&gt;
                  &lt;select class=&quot;form-control name=&quot;selected_batches&quot; multiple&gt;
                      {% for batch in batches %}
                        {% for batch_expiration in batch.annotate_expiration_status %}
                          {% if batch_expiration.expiration_status  == &quot;VALID&quot; %}
                            &lt;option value=&quot;{{batch.id}}&quot;&gt;{{batch.id}} - {{batch_expiration.expiration_status}} - {{batch.status}} - {{batch.available_quantity}}&lt;/option&gt;
                          {% elif batch_expiration.expiration_status == &quot;THREE_MONTHS&quot; %}
                            &lt;option value=&quot;{{batch.id}}&quot;&gt;{{batch.id}} - {{batch_expiration.expiration_status}} - {{batch.status}} - {{batch.available_quantity}}&lt;/option&gt;
                          {% elif batch_expiration.expiration_status == &quot;ONE_MONTH&quot; %}
                            &lt;option value=&quot;{{batch.id}}&quot;&gt;{{batch.id}} - {{batch_expiration.expiration_status}} - {{batch.status}} - {{batch.available_quantity}}&lt;/option&gt;
                          {% elif batch_expiration.expiration_status == &quot;EXPIRED&quot; %}
                            &lt;option value=&quot;{{batch.id}}&quot;&gt;{{batch.id}} - {{batch_expiration.expiration_status}} - {{batch.status}} - {{batch.available_quantity}}&lt;/option&gt;
                          {% endif %}
                          {% endfor %}
                      {% endfor %}
                  &lt;/select&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
             {% endif %}
              &lt;div class=&quot;modal-footer&quot;&gt;
                  &lt;button type=&quot;submit&quot; class=&quot;btn btn-primary&quot; name=&quot;submit&quot;&gt;Save Changes&lt;/button&gt;
                  &lt;button type=&quot;button&quot; class=&quot;btn btn-light border-primary text-primary&quot; data-dismiss=&quot;modal&quot;&gt;Cancel&lt;/button&gt;
              &lt;/div&gt;
          &lt;/form&gt;
  </code></pre>