Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce HyperlinkedHStoreModelSerializer #7

Open
barseghyanartur opened this issue Aug 26, 2015 · 1 comment
Open

Introduce HyperlinkedHStoreModelSerializer #7

barseghyanartur opened this issue Aug 26, 2015 · 1 comment

Comments

@barseghyanartur
Copy link

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?

@barseghyanartur
Copy link
Author

Any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant