-
Notifications
You must be signed in to change notification settings - Fork 0
refactored POST in RateProjects #313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,9 +7,29 @@ | |
|
|
||
|
|
||
| class ProjectScoreCreateSerializer(serializers.ModelSerializer): | ||
| def __init__(self, *args, **kwargs): | ||
| self.criteria_to_get = kwargs.pop("criteria_to_get", None) | ||
| super(ProjectScoreCreateSerializer, self).__init__(*args, **kwargs) | ||
|
|
||
| class Meta: | ||
| model = ProjectScore | ||
| fields = ["criteria", "user", "project", "value"] | ||
| fields = ("criteria", "user", "project", "value") | ||
| validators = [] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. потому что иначе у меня будет автоматическая проверка на unique_together, а это мне не нужно, потому что дальше по коду будет обновление/создание оценок. если тут вылезет ошибка, то create_in_bulk обновить их не сможет |
||
|
|
||
| def get_queryset(self): | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. сериалайзер подгружает данные, оказывается. скорее всего, для каждого объекта в списке отдельно. это не круто. я не доверяю ему, поэтому сделал по своему |
||
| return self.Meta.model.objects.filter( | ||
| criteria__id__in=self.criteria_to_get | ||
| ).select_related("criteria", "project", "user") | ||
|
|
||
| def validate(self, data): | ||
| criteria = data["criteria"] | ||
| ProjectScoreValidate( | ||
| criteria_type=criteria.type, | ||
| value=data.get("value"), | ||
| criteria_min_value=criteria.min_value, | ||
| criteria_max_value=criteria.max_value, | ||
| ) | ||
| return data | ||
|
|
||
|
|
||
| class CriteriaSerializer(serializers.ModelSerializer): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
для этого не было особых причин, но я подумал, что так передавать аргумент в классе сериалайзера будет удобно