Skip to content
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

feat(generic): add DateTimeIntervalCharField #1119

Closed
wants to merge 1 commit into from

Conversation

b1rger
Copy link
Contributor

@b1rger b1rger commented Aug 29, 2024

No description provided.

@b1rger b1rger force-pushed the birger/timespanfield branch from 066b4ae to aec287b Compare August 29, 2024 10:54
@sennierer
Copy link
Collaborator

Is there a specific reason to use DateTimeField instead of DateField?
I guess our main use case (99%) has only dates and no time.

apis_core/generic/fields.py Outdated Show resolved Hide resolved
@b1rger b1rger force-pushed the birger/timespanfield branch 2 times, most recently from d0c6863 to 96e83cf Compare November 20, 2024 10:27
This commit introduces a `FuzzyDateParserField` and a
`FuzzyDateRegexField`.
Both fields are based on the `GenericDateIntervalField`, which adds a
`_from`, a `_sort` and a `_to` field based on the field created. Those
three additional fields contain data that is calculated using either a
parser (in the case of the `FuzzyDateParserField`) or a regex (in the
case of the `FuzzyDateRegexField`).
The default parser for the `FuzzyDateParserField` is the one from the
`apis_core.utils.DateParser` module.
@b1rger b1rger force-pushed the birger/timespanfield branch from 96e83cf to 8184849 Compare November 20, 2024 10:28
@b1rger
Copy link
Contributor Author

b1rger commented Nov 20, 2024

I've reworked the FuzzyDateRegexField as well as the GenericDateIntervalField, which is the base for the regex and the parser fields. I had to redo the contribute_to_class method in the GenericDateIntervalField because there were, again, problems with the database migration. I've now taken inspiration from a solution from django-money, but it would be great if especially adding/removing fields would be battle tested

@sennierer
Copy link
Collaborator

Just got a django.db.utils.OperationalError: duplicate column name: date_of_birth_fuzzy_date_from when using the new field.
Thats what I did:

  • delete the sqlite db
  • add a field called date_of_birth_fuzzy with the GenericDateIntervalField
  • run python manage.py makemigrations
  • run python manage.py migrate

Got the error. Checked the migrations and there is no duplicate field definitions in the migrations.

Copy link
Collaborator

@sennierer sennierer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working as intended. tested with the sample project, both fields. Removed and added fields without any migration issues.

@sennierer
Copy link
Collaborator

We decided to publish the field as its own module.

@sennierer sennierer marked this pull request as draft December 11, 2024 10:13
@b1rger b1rger closed this Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants