Open oTree-org opened 7 years ago
Oh man.
This is actually fixable, I can just wrap add_to_class
when the class is passed to the decorator.
That’s kinda a weird thing to be doing, though: what’s your use case?
I have a framework here where each app has 3 models: Player, Group, Subsession. Usually, 3 models is enough. However, occasionally, users need a variable number of fields on their Player model.
In normal circumstances, one would solve this with a many-to-one relationship via an additional model & a foreign key, but that introduces other complications due to the way my framework is designed (the aim of the framework is to be simple to program, at the expense of some flexibility). So, some users discovered the add_to_class
technique and have been using that (adding fields dynamically in a for-loop). I have now discouraged users from relying on add_to_class
; however, it would be nice if save-the-change supported this because I don't want to break people's existing programs when they upgrade.
Anyway, thanks for the very useful library! It definitely has enabled some nice functionality in my framework 👍
Oh, neat!
Regarding add_to_class
, I just need to go through again and work out what the lifecycle for fields in models is. Pretty sure just wrapping the method is good enough, but since STC has exchanged the nightmares of metaclasses for the weirdness/abhorrence of decorators modifying __bases__
I want to make sure I’m covering all the bases for “normal” additions of fields.
Glad my library’s can help you out!
Great, thank you so much!
I don't know if this is really considered a bug, because
add_to_class
is not even part of Django's public API, it's just internal, so feel free to close if you think this is out of scope. But I thought I would point this out because it used to work in the stable release of save-the-change.I'm using Django 1.8.8 and the latest master of save-the-change.
models.py:
tests.py:
Result: