changes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import os
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
from django.db import models
|
||||
import numpy as np
|
||||
from docx import Document
|
||||
from docx.enum.text import WD_ALIGN_PARAGRAPH
|
||||
@@ -206,13 +206,23 @@ class DocumentGenerator:
|
||||
raise ValueError(f"Could not resolve '{lookup_from}'. It is not a valid API parameter or a reference to another data source.")
|
||||
|
||||
def _get_value_from_object(self, obj, field_path):
|
||||
if obj is None:
|
||||
if not obj:
|
||||
return None
|
||||
|
||||
parts = field_path.split('.')
|
||||
value = obj
|
||||
for part in field_path.replace("__", ".").split("."):
|
||||
for part in parts:
|
||||
if value is None:
|
||||
return None
|
||||
break
|
||||
|
||||
# Lấy thuộc tính từ object
|
||||
value = getattr(value, part, None)
|
||||
|
||||
# KIỂM TRA NẾU LÀ QUAN HỆ NGƯỢC (ForeignKey ngược hoặc ManyToMany)
|
||||
# Trong Django, các quan hệ này trả về một Manager (có method 'all')
|
||||
if hasattr(value, 'all') and not isinstance(value, models.Model):
|
||||
value = value.first() # Tự động lấy bản ghi đầu tiên
|
||||
|
||||
return value
|
||||
|
||||
def fetch_data(self):
|
||||
|
||||
Reference in New Issue
Block a user