-
Notifications
You must be signed in to change notification settings - Fork 208
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
__str__ is broken for MSFList #76
Comments
I can't fix this because it would break what other people expect Why can't you use integers instead of strings? Like so: CHOICE1 = 1
CHOICE2 = 2
CHOICE3 = 3
CHOICE4 = 4
ANSWER_CHOICES = ((CHOICE1, 'A'),
(CHOICE2, 'B'),
(CHOICE3, 'C'),
(CHOICE4, 'D')) Keep in mind that this project is a hack on top of Django's If you cannot use integers, I would recommend using Django's normal many to many relation for this. Sorry I don't have better advice. |
I tried doing that, but I have existing data and it wont convert the types when i migrate, for the existing data. |
Yep, this a major downside to using this project - it becomes difficult if not impossible to upgrade the database around it. 🙁 I'm glad you found a workaround though. Cheers! |
I remember now why i did '1' instead of just 1.
|
Reopened because this is something I might be able to fix. I can simply convert all keys to strings, would that work for you? Try modifying the file in the Vagrant container - change line 136 of return '' if value is None else ",".join(value) and see if that works. If so I'll just have it convert all keys to strings. |
I am working on moving a Django project on py2 to py3 and I got an error related to this, I had some sql migrations produced from changing python versions and removing
it looks like the code you suggested is already in there. The sql migration code produced:
|
@blag It would have been better if this used some standard serialization format like JSON, or at least python's But that would break everything. Why not test if the Also, why use |
+1 |
I'm not sure if this was mentioned here, but in case it helps anyone, this breaks printing out Django model fields, like:
the internal representation, however, is available: So if the issue is not resolved, the string values of MSFList can be accessed with repr() |
If the choices are defined like this,
then the str method returns None, None, None ..
it can be easily fixed by replacing
[msgl.choices.get(int(i)) if i.isdigit() else msgl.choices.get(i) for i in msgl]
with
[msgl.choices.get(i) for i in msgl.choices if i in self.msgl]
The text was updated successfully, but these errors were encountered: