Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何dispatch_list在 Tastypie 中添加自定义字段(在本例中为元代码)?
dispatch_list
恕我直言,更好的方法是在做出响应之前使用函数来覆盖/添加字段到数据:
def alter_list_data_to_serialize(self, request, data): data['meta']['current_time'] = datetime.strftime(datetime.utcnow(), "%Y/%m/%d") return data
您可以向资源添加一个新字段并使用 dehydrate_field_name() 对其进行脱水。