1👍
Without a traceback, I can only take an educated guess as to what the issue actually is.
You are using a standard ModelSerializer
and you are allowing Django REST framework to generate your fields for you. You can introspect the generated fields by printing the output of repr(UploadSerializer())
, but they should look something like this:
class UploadSerializer(ModelSerializer):
url = HyperlinkedIdentityField()
created = DateTimeField()
images = ImageField()
project = ProjectSerializer(many=True, read_only=True)
class Meta:
model = Photo
fields = ('url', 'created', 'images', 'project')
With those fields, a typical dictionary that would be passed back from the serializer should look something like
{
"id": 1,
"url": "http://localhost:8000/api/photos/1/",
"created": "2015-04-22T08:51:11.000Z",
"images": "http://localhost:8000/media/test-image.png",
"project": {
"id": 1,
"created": "2015-04-22T08:51:11.000Z",
"number_of_photos": 1,
"owner": 1
}
}
You’ll notice that this is completely different from what you are passing in. You are passing in the data that would match a serializer that looks like
class UploadSerializer(ModelSerializer):
url = HyperlinkedIdentityField()
created = DateTimeField()
images = SomeCustomImageField()
project = PrimaryKeyRelatedField()
class Meta:
model = Photo
fields = ('url', 'created', 'images', 'project')
So that does answer your secondary question
Did my photo_array variable cause this problem?
Most likely. Now, I don’t actually know what your issue is. It sounds like you are passing a dictionary into a PrimaryKeyRelatedField
, but your serializers don’t actually match up.
- [Answer]-Django: if model has related models (ForeignKey) display Fields in main modelform
- [Answer]-Add or replace a parameter in the query string
- [Answer]-Setting Debug=False on localhost makes the app crash and there's no way to find out what the error is
- [Answer]-Celery vs crontab to call DB shell, which is better to add regular update data into django model database?
- [Answer]-After adding Django CMS to my project, management commands fail with a cache error. How can I fix it?