Code Monkey home page Code Monkey logo

Comments (2)

webjunkie avatar webjunkie commented on September 22, 2024

I can't remember. Maybe it was never needed, e.g. because of the references that the hal format brings, you would want to be working with a model anyways.

from drf-hal-json.

claytondaley avatar claytondaley commented on September 22, 2024

My JSON has an extra layer so I need to use an intermediate Serializer that passes source='*'. For example:

class Patient(Model):
    ...

class Visit(Model):
    subject = FK(Patient)

... needs to produce (properly HAL-formatted) JSON roughly like:

visit = {
    _embedded: {
        "subject": {  # this doesn't exist in the underlying model
            _embedded: {
                "patient": { ... }
            }
        }
    }
}

So I need to interject a serializer:

class PatientSerializer(HalSerializer):
    ...

class SubjectSerializer(HalSerializer):
    patient = PatientSerializer(source='*')

class VisitSerializer(HalSerializer):
    subject = SubjectSerialilzer()

Obviously, there's no model for the SubjectSerializer so a ModelSerializer doesn't seem to make sense. My test cases pass if I pull all of the methods from HalModelSerializer into a separate HalSerializerMixin, but I need to make sure I'm fully validating the structure of the data before I PR the change.

from drf-hal-json.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.