Generated `@id` field is uncorrect for custom QuerySet in @property annoted method of Model
There a whole logic in djangoldp
to generate HTTP API URLs form models (see here). In most cases, this generated URL is the same as the generated @id
field of serialized object.
This can cause problem when a model features a computed field generated with @property
. For instance:
class SomeModel(djangoldp.models.Model):
# some fields here
@property
def some_computed_field:
return SomeOtherModel.object.filter(some_filter=some_calue).all()
class Meta:
serializer_fields = [..., "some_computed_field"]
Here, some_computed_field
, will get serialized as such:
GET /api/somemodel/:id
{
// fields here
some_computed_field: {
"@id": "/api/somemodel/:id/some_computed_field"
// The rest of serialized SomeOtherModel fields
}
}
In this case, some_computed_field
's @id
field has nothing to do with actual Django URLs because the URL generation mecanism described above is not triggered since the property is not an actual field.
Ping @alexandre and @sylvain