2
收到此錯誤: - '餐廳' 對象有沒有屬性 'menu_here__starters'如何將外鍵字段導出到Django Views.py中的Excel中?
我使用的Django的Excel庫
在我Models.py
類餐廳(models.Model):
name = models.CharField(max_length=20)
area = models.CharField(max_length = 30)
menu_here = models.ForeignKey(Menu)
類菜單(models.Model):
starters = models.CharField(max_length = 50)
desserts = models.CharField(max_length = 50)
以我Views.py
DEF download_excel_4(請求):
query_set = Restaurant.objects.all() # Foreign column is Menu
column_names = ['menu_here__starters','menu_here__desserts' ]
return excel.make_response_from_query_sets(
query_set,
column_names,
'xls',
file_name="Restaurant With Complete Menu Database"
)
謝謝!這個答案很簡單! –