Default Behavior

By default, conduit will serialize your model’s related object fields by their raw value. A ForeignKey field will produce the primary key of your related object. A ManyToMany field will product a list of primary keys.

An example resource Foo has one FK and one M2M field:

class Foo(models.Model):
        name = models.CharField(max_length=255)
        bar = models.ForeignKey(Bar)
        bazzes = models.ManyToManyField(Baz)

Will produce a detail response looking like this:

        "name": "My Foo",
        "bar": 45,
        "bazzes": [5, 87, 200],
        "resource_uri": "/api/v1/foo/1/"

When updating a ForeignKey field, conduit will set the model’s [field]_id to the integer you send it. Be careful not to set it to a nonexistent related model, since there are not constraint checks done when saved to the database.

Similarly, when updated a ManyToMany field and give it a nonexistent primary key, the add will silently fail and the invalid primary key will not enter the ManyToMany list.


Updating raw primary keys will not produce errors for invalid keys.