It isn't entirely clear what you're trying to do. Do you want to
change the Django serializers so that they output:
"type": "TemplateType3"
If this is the case, then you will need to write your own serializer.
Django serializes objects in a specific way, optimized for
deserialization later on as fixtures. This output format won't suit
many applications. If you need a different format, you will need to
write a serializer that outputs in the format you require. Django
ships with SimpleJSON, so you can build serialized output from
primitives if need be. You could also use Django's serialization
library to write your own serializer that outputs in a format of your
choice. If your desired output format is similar to Django's default
format, you may find that you can use django/core/serializers/json.py
as a starting point for this implementation.
Alternatively, are you trying to manipulate a deserialized object in
some way? If this is the case, you will need to provide more specific
details on what it is you are trying to achieve.
Yours
Russ Magee %-)
The serializer is decoupled from the Model API, so your question is
unrelated to the model API. Serialization exploits the model metatdata
embedded in models; the issue in this case is that the data extracted
from the model by the serializer doesn't meet your requirements. You
want to have a different serialization format (i.e., you want to roll
out serialized objects in a different format to that provided by
default). This means you will need to write your own serializer.
Looking for deeper solutions to this problem -
Ticket #4656 possibly describes part of your problem - this ticket
describes an enhancement that would allow the serializer to follow.
This would be much like the select_related() operator on querysets,
but for serialization. This ticket hasn't seen any activity for a
while, but it has been accepted for inclusion as soon as a working
implementation is available.
There is also a lingering ticket idea floating around - it has been
suggested many times that Django's serializers are not flexible enough
- that your use case should be a matter of configuring Django's
serializer, rather than writing a new serializer from scratch. In
principle, I have no objection to this idea - but I am yet to see a
good proposal for what such configuration would look like.
> I'll keep tinkering... Let me know if you have any ideas.
Let me know if you have any :-)
Yours
Russ Magee %-)