Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Fix size and pups attributes for Bats #22

Open
mcab opened this issue Mar 26, 2019 · 2 comments
Open

Fix size and pups attributes for Bats #22

mcab opened this issue Mar 26, 2019 · 2 comments

Comments

@mcab
Copy link
Owner

mcab commented Mar 26, 2019

When using *RangeField in specific PostgreSQL fields, the bounds are always defined as [) (inclusive first number, exclusive last number). This can be changed in the database, but Django does not support changing those bounds.

So, when users enter in data in the administration panel, erroneous behavior can occur.

Say for example, a bat only has one pup per year. That would be entered in as 1 - 1 in the Wagtail interface. Stored in the database, that's [1, 1), which is an invalid range, and defaults to null for the value. This shouldn't be the case.

One solution would be to break it up into two separate fields (min/max_(size|pups)), and create a serializer that ties the two fields for the API, like

"pups": {
    "min": 1
    "max": 1
}
@mcab
Copy link
Owner Author

mcab commented Mar 26, 2019

This isn't as high priority, because the Bat Admin panel isn't necessary for demonstration purposes.

@mcab
Copy link
Owner Author

mcab commented Apr 14, 2019

This should be done by replacing size and pups with something utilizing DecimalField.

min_size = models.DecimalField(max_digits=3, decimal_places=1)
max_size = models.DecimalField(max_digits=3, decimal_places=1)

The way to provide a custom validator for this (min_size <= max_size) would be to implement a clean() method on it. Probably not worth the trouble, unless tests are written for model validation.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant