'zoneinfo.ZoneInfo' object has no attribute 'localize'

I was trying to add daterangefilter in my admin.

below my model

from django.db import models
from order.models import Order, OrderItem
from payment.models import PaymentDetails
from plan import constants as plan_constant

class SubjectPlanManager(models.Manager):
    def get_queryset(self):
        # Filter for only "subject plan" data (mapped to 2)
        return super().get_queryset().filter(plan__plan_type=plan_constant.PLAN_TYPE_MAPPING["subject plan"])
    
class SalesDashboardOrderItem(OrderItem):
    objects = SubjectPlanManager()
    class Meta:
        proxy = True
        verbose_name = "Sales Dashboard Item"
        verbose_name_plural = "Sales Dashboard Items"

    @property
    def payment_details(self):
        # Get the PaymentDetails related to this OrderItem
        return PaymentDetails.objects.filter(order_id=self.order).first()

    @property
    def transaction_id(self):
        # Return the transaction ID from PaymentDetails
        payment = self.payment_details
        return payment.transaction_id if payment else "N/A"

    @property
    def payment_status(self):
        # Return the payment status from PaymentDetails
        payment = self.payment_details
        return payment.state if payment else "N/A"

    @property
    def payment_amount(self):
        # Return the payment amount from PaymentDetails
        payment = self.payment_details
        return payment.amount if payment else 0
    

below my admin model

from django.contrib import admin
from django.utils import timezone
from sales_dashboard.models import SalesDashboardOrderItem
from plan import constants as plan_constant
from django.utils.translation import gettext_lazy as _
from rangefilter.filter import DateRangeFilter
from datetime import datetime
from dateutil import tz
from django.utils import timezone
from medway.log import Log

logger = Log().get_default_logger()



class SalesDashboardOrderItemAdmin(admin.ModelAdmin):
    list_display = (
        'plan',
        'order',
        'price',
        'payment_amount'
    )

    # Optional: Add filters for better usability
    list_filter = (
        ('plan_start_date', admin.DateFieldListFilter),
        ('plan_start_date', DateRangeFilter),
        'plan',
    )

    def get_queryset(self, request):
        queryset = super().get_queryset(request)
        return queryset.filter(plan__plan_type=plan_constant.PLAN_TYPE_MAPPING["subject plan"])

    def get_plan_start_date(self, obj):
        logger.debug("get_plan_start_date called with obj: %s", obj)
        if obj.plan_start_date:
            if timezone.is_naive(obj.plan_start_date):
                aware_dt = timezone.make_aware(obj.plan_start_date, timezone.get_default_timezone())
            else:
                aware_dt = obj.plan_start_date
            return timezone.localtime(aware_dt)
        return None
    get_plan_start_date.short_description = _('Plan Start Date')


admin.site.register(SalesDashboardOrderItem, SalesDashboardOrderItemAdmin)

Error:

 [2024-09-05 09:30:30,826] [ERROR] [40 140113912736568] [Log ID:67c307e574a1432f9dae15f11adc7830] [Phone Number:None] (exception.process_exception:33) Execption on server, Ex: 'zoneinfo.ZoneInfo' object has no attribute 'localize'

Welcome @ashuvik04 !

Side note: When posting code, templates, error messages, or other preformatted text here, enclose the code between lines of three backtick - ` characters. This means you’ll have a line of ```, then your code, then another line of ```. This forces the forum software to keep your code properly formatted. (I’ve taken the liberty of fixing your original post for you.)

Having the complete traceback would likely be helpful here.

@KenWhitesell Thanks for the tip on formatting! I’ll use the three backticks for code and include the full traceback in my next post. Appreciate the help!