다형성 모델을 직렬화하고 싶지만 그의 기본 유형 필드 만 다형성이 아닌 직렬화됩니다.Django - 다형성 모델 직렬화
나는 보통 여기 내 모델 객체를 직렬화 및 JSON로 보내지 만 위해 할 방법 models.py
class Folder(PolymorphicMPTTModel):
parent = PolymorphicTreeForeignKey('self', null=True, blank=True, related_name='children')
name = models.CharField(max_length=50)
class File(Folder):
srs_wkt = models.CharField(max_length=1000, blank=True, null=True)
views.py
from django.core import serializers
from django.core.serializers.json import DjangoJSONEncoder
file = File.objects.get(pk=1)
serialized = serializers.serialize('python', [file,])
response = json.dumps({'file':file}, cls=DjanJSONEncode)
return HttpResponse(response, content_type="application/json")
는 JSON 객체 만 srs_wkt있다 필드가 아니라 이름.
다형성 모델을 직렬화하는 방법이 있습니까?