Opened 18 years ago

Closed 17 years ago

#4633 closed (wontfix)

Unable to serialize a not yet saved model which has many-to-many relation.

Reported by: Bear Owned by: nobody
Component: Core (Serialization) Version: dev
Severity: Keywords: model, serialize, many-to-many
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If I try to serialize a not yet saved model which has many-to-many relation, it will raise ValueError while serialize many-to-many field.

for instance:

from django.contrib.auth.models import User

u = User(username="bear", password="bear", email="blp330@…")

from django.core import serializers

serializers.serialize("json", [u])

=>

ValueError: <class 'django.contrib.auth.models.Group'> instance needs to have a
primary key value before a many-to-many relationship can be used.

This makes inconvenient while use ajax in some situation.

Change History (1)

comment:1 by Russell Keith-Magee, 17 years ago

Resolution: wontfix
Status: newclosed

Serialization is only intended for use of objects that are saved and in the database. Unless you can provide an example of where AJAX would require the serialization of an incomplete object, I'm marking this wontfix.

Note: See TracTickets for help on using tickets.
Back to Top