refactor: added print_question method - #7
Conversation
| "type": "question", | ||
| "text": self.text, | ||
| "options": [opt.answer for opt in self.options], | ||
| "options": [opt.ask() for opt in self.options], |
There was a problem hiding this comment.
I put this back to not expose the correct value to the admin and client.
| """Return a dictionary representation of the option, used when sending json.""" | ||
| return { | ||
| "answer": self.answer, | ||
| "correct": self.correct, |
There was a problem hiding this comment.
What about changing this line to the default False value, so the actual correctness is still hidden?
| "correct": self.correct, | |
| "correct": False, |
I look forward to the discussion on Thursday.
There was a problem hiding this comment.
Yes, we can do it like that.
Optionally we can check some method how to adjust the serialization (model_dump) - we can rewrite the correct field there. There should be a possibility of serialization with and without parameters.
|
Maybe we should use Pydantic serialization approach. And then call self.model_dump(context="for players") in the method ask for Question. |
|
We can try something like that: @field_serializer('correct', mode='plain')
@classmethod
def hide_right_answers(cls, v: bool, info: FieldSerializationInfo):
return False if info.context == "for players" else vUsage: |
No description provided.