|
|
@ -1499,6 +1499,13 @@ class AdminBookReferenceDetailSerializer(serializers.ModelSerializer): |
|
|
cleaned_list.append(item) |
|
|
cleaned_list.append(item) |
|
|
mutable_data[list_field] = cleaned_list |
|
|
mutable_data[list_field] = cleaned_list |
|
|
|
|
|
|
|
|
|
|
|
if "authors" in mutable_data and ("author" not in mutable_data or mutable_data.get("author") is None): |
|
|
|
|
|
auth_val = mutable_data.get("authors") |
|
|
|
|
|
if isinstance(auth_val, list): |
|
|
|
|
|
mutable_data["author"] = auth_val[0] if len(auth_val) > 0 else None |
|
|
|
|
|
elif auth_val and str(auth_val).isdigit(): |
|
|
|
|
|
mutable_data["author"] = int(auth_val) |
|
|
|
|
|
|
|
|
for int_field in ["number_page", "order", "type", "tag", "author"]: |
|
|
for int_field in ["number_page", "order", "type", "tag", "author"]: |
|
|
if int_field in mutable_data: |
|
|
if int_field in mutable_data: |
|
|
val = mutable_data.get(int_field) |
|
|
val = mutable_data.get(int_field) |
|
|
@ -1517,6 +1524,17 @@ class AdminBookReferenceDetailSerializer(serializers.ModelSerializer): |
|
|
|
|
|
|
|
|
return super().to_internal_value(mutable_data) |
|
|
return super().to_internal_value(mutable_data) |
|
|
|
|
|
|
|
|
|
|
|
def to_representation(self, instance): |
|
|
|
|
|
ret = super().to_representation(instance) |
|
|
|
|
|
if instance.author_id: |
|
|
|
|
|
ret["authors"] = [instance.author_id] |
|
|
|
|
|
if ret.get("author_detail"): |
|
|
|
|
|
ret["authors_detail"] = [ret["author_detail"]] |
|
|
|
|
|
else: |
|
|
|
|
|
ret["authors"] = [] |
|
|
|
|
|
ret["authors_detail"] = [] |
|
|
|
|
|
return ret |
|
|
|
|
|
|
|
|
def create(self, validated_data): |
|
|
def create(self, validated_data): |
|
|
subject_area = validated_data.pop("subject_area", []) |
|
|
subject_area = validated_data.pop("subject_area", []) |
|
|
validated_data.pop("remove_thumbnail", False) |
|
|
validated_data.pop("remove_thumbnail", False) |
|
|
|