We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have two models Index is referencing Posting as follows:
Index
Posting
class Posting(models.Model): document = models.ForeignKey(Tweet) positions = mongo_fields.ListField() class Index(models.Model): token = models.CharField(max_length=10, unique=True) postings = mongo_fields.ListField(mongo_fields.EmbeddedModelField('Posting')) term_frequency = models.IntegerField()
when I serialize Index objects I get an error
Traceback (most recent call last): File "<input>", line 1, in <module> serializers.serialize('json', Index.objects.all()) File ".../django/core/serializers/__init__.py", line 91, in serialize s.serialize(queryset, **options) File ".../django/core/serializers/base.py", line 54, in serialize self.end_serialization() File ".../django/core/serializers/json.py", line 21, in end_serialization simplejson.dump(self.objects, self.stream, cls=DjangoJSONEncoder, **self.options) File ".../simplejson/__init__.py", line 261, in dump for chunk in iterable: File ".../simplejson/encoder.py", line 600, in _iterencode for chunk in _iterencode_list(o, _current_indent_level): File ".../simplejson/encoder.py", line 455, in _iterencode_list for chunk in chunks: File ".../simplejson/encoder.py", line 568, in _iterencode_dict for chunk in chunks: File ".../simplejson/encoder.py", line 568, in _iterencode_dict for chunk in chunks: File ".../simplejson/encoder.py", line 455, in _iterencode_list for chunk in chunks: File ".../simplejson/encoder.py", line 622, in _iterencode o = _default(o) File ".../django/core/serializers/json.py", line 58, in default return super(DjangoJSONEncoder, self).default(o) File ".../simplejson/encoder.py", line 239, in default raise TypeError(repr(o) + " is not JSON serializable") TypeError: <Posting: {'positions': [12], 'document': u'5218d561c454fe2ae837019c', 'id': None}> is not JSON serializable
while Posting objects is serializable
x = Posting.objects.create(document=tweet, positions=[1,2,3]) serializers.serialize('json', [x]) '[{"pk": "52194e0ec454fe20bbcb841d", "model": "indexer.posting", "fields": {"positions": [1, 2, 3], "document": "5218d561c454fe2ae83701a4"}}]'
I think the problem is that Posting objects which are embedded in Index have id == None
id == None
The text was updated successfully, but these errors were encountered:
No branches or pull requests
I have two models
Index
is referencingPosting
as follows:when I serialize
Index
objects I get an errorwhile
Posting
objects is serializableI think the problem is that
Posting
objects which are embedded inIndex
haveid == None
The text was updated successfully, but these errors were encountered: