Unable to serialize a not yet saved model which has many-to-many relation.
|Reported by:||Bear||Owned by:||nobody|
|Severity:||Keywords:||model, serialize, many-to-many|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.
from django.contrib.auth.models import User
u = User(username="bear", password="bear", email="blp330@…")
from django.core import serializers
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.