How to serialize a single model instance AND include the primary key
<p>I have a single model instance <code>obj</code>. I want to serialize it, and for the primary key to be included in the serialized data.</p>

<ul>
<li><p><code>django.core.serializers.serializer</code> wants a queryset (throws an
error that <code>ojb</code> isn't iterable).</p></li>
<li><p>I simply cannot coerce
<code>django.forms.model_to_dict</code> into including    the primary key in the
serialized object, even explicitly calling: <code>model_to_dict(obj,
fields=['pk'])</code> or <code>model_to_dict(obj, fields=['id'])</code></p></li>
</ul>

<p>How do I do this?</p>

<p><code>model_to_dict</code> will not dump fields that have <code>editable=False</code> (so, for example, the primary key). It is possible to manually construct the object serialization by:</p>

<pre><code>{field.name: field.value_from_object(obj) for field in obj._meta.fields}
</code></pre>

python django serialization