# Path: apps/cryptonews/models/db.py
# class News(models.Model):
#     slug = fields.RandomCharField(
#         length=12,
#         unique=True,
#         include_alpha=False,
#         db_index=True,
#         editable=False,
#     )
#     title = models.CharField(max_length=1024)
#     content = models.TextField(blank=True, default="")
#     published_at = models.DateTimeField(default=timezone.now, db_index=True)
#     origin_link = models.URLField(
#         max_length=1024, null=True, blank=True, unique=True
#     )
# 
#     class Meta:
#         ordering = ["-published_at"]
# 
#     def __str__(self):
#         return f"{self.title} - {self.published_at} - {self.origin_link}"
# 
#     @cached_property
#     def domain(self):
#         o = parse.urlparse(self.origin_link)
#         return o.netloc


from rest_framework import serializers
from .models import News


class CryptoNewsSerializer(serializers.ModelSerializer):
    domain = serializers.CharField(read_only=True)

    class Meta:
        model = News
        # exclude = ["id"]
        fields = "__all__"
        read_only_fields = ["id", "slug"]


class PushExchangeAnnSerializer(serializers.ModelSerializer):
    channel = serializers.CharField(
        default="ExchangeAnnChannel", read_only=True
    )

    class Meta:

# Path: apps/cryptonews/models/db.py
# class News(models.Model):
#     slug = fields.RandomCharField(
#         length=12,
#         unique=True,
#         include_alpha=False,
#         db_index=True,
#         editable=False,
#     )
#     title = models.CharField(max_length=1024)
#     content = models.TextField(blank=True, default="")
#     published_at = models.DateTimeField(default=timezone.now, db_index=True)
#     origin_link = models.URLField(
#         max_length=1024, null=True, blank=True, unique=True
#     )
# 
#     class Meta:
#         ordering = ["-published_at"]
# 
#     def __str__(self):
#         return f"{self.title} - {self.published_at} - {self.origin_link}"
# 
#     @cached_property
#     def domain(self):
#         o = parse.urlparse(self.origin_link)
#         return o.netloc


# Path: apps/cryptonews/serializers.py
from rest_framework import serializers
from .models import News



class CryptoNewsSerializer(serializers.ModelSerializer):
    domain = serializers.CharField(read_only=True)

    class Meta:
        model = News
        # exclude = ["id"]
        fields = "__all__"
        read_only_fields = ["id", "slug"]


class PushExchangeAnnSerializer(serializers.ModelSerializer):
    channel = serializers.CharField(
        default="ExchangeAnnChannel", read_only=True
    )

    class Meta:

        model = News