class ReportSerializer(serializers.HyperlinkedModelSerializer): root_model = serializers.PrimaryKeyRelatedField( queryset=Report.allowed_models()) root_model_name = serializers.StringRelatedField(source='root_model') user_created = UserSerializer(read_only=True) class Meta: model = Report fields = ('id', 'name', 'modified', 'root_model', 'root_model_name', 'user_created')
def handle(self, *args, **options): """The 'main' method of this command. Gets called by default when running the command.""" admin = User.objects.get(username='******') report = Report( name='Sample award report (all fields)', slug='sample-award-report-all-fields', description= 'Copy this report to add your own filters for your own reports', root_model=ContentType.objects.get(app_label="awards", model="award"), user_created=admin, user_modified=admin, ) report.save() self.add_display_fields_to_report(report, Award) self.add_display_fields_to_report(report, Proposal) self.add_display_fields_to_report(report, AwardAcceptance) self.add_display_fields_to_report(report, AwardNegotiation) self.add_display_fields_to_report(report, AwardSetup) self.add_display_fields_to_report(report, AwardManagement) self.add_display_fields_to_report(report, AwardCloseout) self.add_filter_fields_to_report(report) empty_report = Report( name='Sample award report (add your own fields)', slug='sample-award-report-no-fields', description= 'Copy this report to add your own fields and filters for your own reports', root_model=ContentType.objects.get(app_label="awards", model="award"), user_created=admin, user_modified=admin, ) empty_report.save() self.add_filter_fields_to_report(empty_report) self.stdout.write('Report setup complete')