from django.db import models
from .common import CreateCommon
from django.urls import reverse
from django.utils.http import urlencode


class SearchHistory(CreateCommon):
    """存储搜索历史数据"""

    class Meta:
        verbose_name = '搜索历史'
        verbose_name_plural = verbose_name

    def __str__(self):
        return f"{self.title}"

    def get_absolute_url(self):

        # 使用urlencode处理参数
        base_url = reverse('search')
        params = urlencode({'key': self.title})
        return f"{base_url}?{params}"
