Skip to content

Introduce HyperlinkedHStoreModelSerializer #7

Open
@barseghyanartur

Description

@barseghyanartur

Hello,

Consider the following structure:

models.py

from django.db import models
from django_hstore import hstore


class Brand(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField(null=True, blank=True)

class Product(models.Model):
    title = models.TextField()
    description = models.TextField(null=True, blank=True)
    brand = models.ForeignKey(Brand)

class ProductAdditionalData(models.Model):
    product = models.ForeignKey(Product)
    timestamp = models.DateTimeField(auto_now=True, null=True, blank=True)
    data = hstore.DictionaryField(null=True, blank=True)

serializers.py

from rest_framework import serializers

from rest_framework_hstore.serializers import HStoreSerializer

class BrandhSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Brand
        fields = ('title', 'description',)


class ProductSerializer(serializers.HyperlinkedModelSerializer):
    class Meta:
        model = Product
        fields = ('title', 'description', 'brand')


class ProductAdditionalDataSerializer(HStoreSerializer):
    class Meta:
        model = ProductAdditionalData
        fields = ('product', 'timestamp', 'data',)

In the ProductAdditionalDataView (which uses ProductAdditionalDataSerializer) I would like to have relation to the product hyperlinked to ProductView, but that doesn't work. For ProductView, which uses the ProductSerializer (inherited from HyperlinkedModelSerializer) it does work.

Thus, the feature request: could you consider making a HyperlinkedHStoreModelSerializer which solved the problem?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions