Subclass the __init__
function in your ReportResource and set the use_in
flag there, now that your fields have been populated:
def __init__(self, *args, **kwargs):
# Call the object's parent, which will set up and populate
# the Resource fields from the queryset provided
super(ReportResource, self).__init__(*args, **kwargs)
# Now loop through the fields of the resource, and when we
# find the one we only want to be shown in the detail view,
# set its use_in attr appropriately
for field_name, field_object in self.fields.items():
if field_name == 'report_data':
field_object.use_in = 'detail'
(Generically, you could have this in a separate class that you mix in, and perhaps it could read the list of what you want from a variable in Meta, but this should do what you ask.)
The same sort of loop through self.fields.items()
is used for the use_in
check in Resource's full_dehydrate method, as you can see from the source code of resources.py
.