Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I believe the error is here:</p> <pre><code>def __init__(self, *args, **kwargs): super(AutoTreeItemField, self).__init__(TreeItem, null=True) </code></pre> <p>You should pass through the other (unnamed) args:</p> <pre><code>def __init__(self, *args, **kwargs): if not args: args = [TreeItem] options = {'null': True} options.update(kwargs) super(AutoTreeItemField, self).__init__(*args, **options) </code></pre> <p><strong>Edit</strong></p> <p>I probably found something. In a normal FK, say it's declared as</p> <pre><code>other = models.ForeignKey(OtherClass) </code></pre> <p>the type of instance.other is OtherClass, not ForeignKey. OtherClass instances have a <code>_meta</code> attribute, because they <strong>are</strong> models.</p> <p>In your case it seems (from the <code>django.core.serializers.python</code> traceback) that it is trying to serialize the AutoTreeItemField instance (that is of course not serializable) instead of the related TreeItem.</p> <p>From the <code>django.core.serializers.python</code> module, l. 48:</p> <pre><code>def handle_fk_field(self, obj, field): related = getattr(obj, field.name) </code></pre> <p>and you have in the contribute_to_class method:</p> <pre><code>setattr(cls, self.name, self) </code></pre> <p>while in the ForeignKey contribute_to_class method:</p> <pre><code>setattr(cls, self.name, ReverseSingleRelatedObjectDescriptor(self)) </code></pre> <p>Given that a ForeignKey instance is not a RelatedObjectDescriptor instance, all django serializers expect to find the latter, that are instances (or return instances upon being called their <code>__get__</code> method) of actual models.</p> <p>In the end, you'd probably remove the setattr(cls...) line from the method. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload