yunojuno / django-charid-field

Provides a prefixable, string-based ID field for your Django models. Supports cuid, ksuid, ulid & more.
MIT License
34 stars 4 forks source link

Various bug fixes and API changes for v0.2.0 #4

Closed djm closed 3 years ago

djm commented 3 years ago

If applied this PR will..

1) The code which ensures all defaults get the prefix applied to them has been changed to work in all scenarios. Previously form field init would get the raw default, leading to the situation in #2.

2) Validation is now not carried out by to_python, but instead by the validate method. to_python is called during ORM lookups and as such was not the appropriate place for this particular style of validation (checking of prefix) as it would cause ORM lookups such as filter() and get_object_or_404 to blow up. Fixes #3.

3) Remove support for callable prefixes, when I developed this I assumed that a callable prefix would allow us to have a single field on an abstract = True Django model, and that the callable called in contribute_to_class would be passed the details of the concrete Django modal subclassing the abstract. This is however not the case, the method gets passed the details of the Abstract model and thus dynamically calculating any prefix based on some concrete model detail is impossible. Therefore the feature has been removed and we now have simple string prefixes only.