-
Notifications
You must be signed in to change notification settings - Fork 23
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
Add choice fields #15
base: master
Are you sure you want to change the base?
Conversation
This is more backwards compatible up to Django 2.0 and 2.1.
register_serializer() is available on Django 2.2 and up, and generally produces a better/more readable migrations than deconstructible(), which had been available longer. The migration should be compatible either way, so let's prefer a more readable migration when it's available.
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.
Note that I am still waiting for @GigiusB to submit a new PR for his version of django-admin integration, so I'll have to run this one by him. He's currently putting a lot of effort in and it would be a shame for that to go to waste.
Nevertheless, what I'm confused about is what happens in the admin UI when there aren't any choices in a relativedeltafield. Where's the code that makes this happen? It just handles it by default?
Anyway, this doesn't seem to work as intended. When you click on "add" for interval (without choices), it shows you a form and you must type in an ISO interval. But then when you type in, say P5M and click "save and continue editing", it shows you relativedelta(months=+5), which cannot be saved. I think this has something to do with the RelativeDeltaSerializer
.
|
||
elif has_migration_deconstructible: | ||
# Django 2.1 and lower | ||
deconstructible(relativedelta) |
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.
Why is this migration stuff needed, exactly?
I've used django-relativedelta in a few projects and it never required any special code.
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.
makemigrations
does not know how to serialise relativedelta
if the model fields' arguments contains a relativedelta
object, and this tells it how. choices
are defined by a "list of (relativedelta, str) pair", so we need this when choices
is defined. Without this, you'd get an error when doing makemigrations
:
ValueError: Cannot serialize: relativedelta(days=+1)
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/3.1/topics/migrations/#migration-serializing
Without this serialisation stuffs, default
wouldn't work either RelativeDeltaField(default=relativedelta(days=1))
.
Thank you for reviewing my PR.
When the model field isn't restricted by My PR only implements admin editing and ModelForm generation when the field has Given that |
I know there has been a couple attempts on making a form field for this library, including a very recent one by GigiusB, and a couple older ones by lancondrej and ChandlerBent.
This PR implements a slightly different requirement than those, in that this adds a
RelativeDeltaChoiceField
form field that uses<select>
widget to pick from a list of predetermined durations instead of a free field arbitrary durations.