def validate_category(self, project, category_id):
        errors = []
        category = None
        try:
            category = project.categories.get(pk=category_id)
            if category.status == 'inactive':
                errors.append('The category can not be used because it is '
                              'inactive.')
            else:
                self._validated_data['meta']['category'] = category
        except Category.DoesNotExist:
            errors.append('The category can not be used with the project '
                          'or does not exist.')

        if errors:
            self._errors['category'] = errors

        return category
Validates if the category can be used with the project
dataset/ETHPy150Open ExCiteS/geokey/geokey/contributions/serializers.py/ContributionSerializer.validate_category