Self referencing table
scripter-co opened this issue · 2 comments
scripter-co commented
Hey,
I'm trying to create a files table, which will hold records for primary files and it's child files (files assosacted with the primary files).
Basically, something simple like
----------------------------------------------------
| ID | Filename | ParentID |
----------------------------------------------------
I've defined my model like:
class File(Model):
has_many = ('File',)
and then called it like:
child_file = models.File.create(processing=False, type=output_file['type'], file=file_record, original_filename=filename)
however, when trying to call this, I'm getting the following error:
TypeError: <File: 9f353838-f362-454d-8d96-126451eae882> is not JSON serializable
linkyndy commented
You also need to create the inverse relation if you wish to create models like this. You need to define the belongs_to
relation. Currently, your File
model doesn't know that it can receive a file
key that is part of a relation. It treats it like a normal field and tries to JSON serialize its contents.
scripter-co commented
You are completely right.