I'm sorry, but the leap to "full" serializers *really* is a big leap.
With all due respect, and acknowledging that you've built a project
that scratches your personal itches - I don't consider
django-full-serializers to be anything close to the sort of "full"
serializer that would like to see in Django. To be sure -
django-full-serializers contains a whole lot of features that Django's
serializers doesn't have, but IMHO, it's also missing a whole lot of
really important features.
I don't consider the task of "full" serialization to be just a matter
of allowing extra fields and attributes, plus allowing arbitrary depth
of serialization. I consider "full" serialization to be allowing
complete configuration of the serialization process. For example, you
should be able to define a serializer that *doesn't* require the top
level structure of serialized objects to include "pk", "model" and
"fields". I would expect that the following to be a completely
legitimate output of a configured serializer for content types:
[ ('auth', 'user'), ('auth','permissions'), ('admin','logentry') ]
This obviously isn't enough detail to deserialize anything, but this
sort of sanitized output could be extremely useful to an AJAX
consumer.
Getting this degree of customization will be a big job, but that's
what I'm thinking about when I think about "full" serialization.
> Your patch also makes this the default behaviour for a serializer. So
> how then does a consumer (other than the Django deserializer) of the
> serialized output know that "('auth', 'user')" belongs to the
> contenttypes.contenttype model?
The same way that Django's deserializer knows - because it has access
to some metadata. I don't think it's unreasonable to expect that
consumers of serialized data should have some sort of understanding of
what they are consuming - either hardcoded knowledge about the
datatypes they are receiving, or via some metadata description.
Of course, you could embed that metadata into the serialization -
which is what django-full-serializers does. And this sort of embedding
should be possible. But it's not the *only* way to serialize data.
> I'm also uncomfortable putting this in the model & manager, but I'm
> not clear on the other potential use cases. Making it as an option in
> the serializer sits better with me.
The non-serialization use case is that a surrogate key is essentially
a useful way of referring to an object instance. ContentType provides
manager level helpers to retrieve content types based on a Model
instance - this is just extending those capabilities. As a bonus, it
happens to be useful for serialization.
> Would you see full serialization replacing the surrogate keys strategy
> in future or would Django be stuck with supporting both and their
> intermingled code?
Replacing it, at an option. "Full" serialization to me means that you
can choose exactly how a foreign key is serialized and under what
circumstances that would occur. This could mean:
* Use foreign keys always
* Use foreign keys unless a surrogate is available
* Use a custom scheme described by some user-defined function
* Use a combination of these approaches depending on context.
Yours
Russ Magee %-)