<gh_stars>1-10
from rest_framework import serializers

from blocks.models import Block


class BlockSerializer(serializers.HyperlinkedModelSerializer):
    age = serializers.ReadOnlyField()

    transactions = serializers.HyperlinkedRelatedField(
        many=True,
        read_only=True,
        view_name='transaction-detail',
    )

    class Meta:
        model = Block
        fields = (
            "prev_hash",
            "height",
            "version",
            "merkle_root",
            "timestamp",
            "bits",
            "nonce",
            "num_transactions",
            'transactions',
            "hash",
            "age",
        )

from rest_framework import serializers

from blocks.models import Block


class BlockSerializer(serializers.HyperlinkedModelSerializer):
    age = serializers.ReadOnlyField()

    transactions = serializers.HyperlinkedRelatedField(
        many=True,
        read_only=True,
        view_name='transaction-detail',
    )

    class Meta:
        model = Block
        fields = (
            "prev_hash",
            "height",
            "version",
            "merkle_root",
            "timestamp",
            "bits",
            "nonce",
            "num_transactions",
            'transactions',
            "hash",
            "age",
        )