seawolf42 / django-lookup-tables Goto Github PK
View Code? Open in Web Editor NEWLicense: Other
License: Other
There should be a built-in validator for fields.LookupTableItemField
that confirms the item being related to is actually of the correct type prior to saving.
Learned the pattern being used for lookup tables is an anti-pattern; this needs to be re-architected to use a new approach:
on_delete
are implemented consistently in the app and to continue to provide correct choices
logicchoices
logicThe field should honor the default='xxx'
parameter just like a CharField
does; if present, and if no value is provided for the field, it should set itself to the LookupTableItem
having this value. If that item does not exist, it should be created.
If a default is provided and the table is being created, the item named <DEFAULT>
that is auto-created should instead be named the value of the default
parameter.
I think the right way for a model to reference a lookup table and the selected item in that table is to use a custom ModelField
implementation. The field will contain a foreign key to the LookupTableItem
and the field definition will include a parameter that maps the field to a specific LookupTable
instance (which determines which items can be selected).
It would be very convenient if a user could use the field like this:
class MyModel(models.Model):
lookup = LookupTableItemField(table_ref='abc')
instance = MyModel.objects.get(pk=some_pk)
instance.lookup = 'the name of an option'
instance.save()
This requires marshaling the field to find the right LookupTableItem
for that value. If no such item exists, this should be an error.
Lookup tables are separate tables, but they should be administered as if they were all a common thing, with a single admin entry point (/admin/lookuptable/
?) that gives a list of all tables, and clicking on a table lets you manage the list of items for that table.
Sometimes drop-downs are enough to annotate a model, but the data associated with the drop-down should include additional metadata that can be adjusted to annotate values. For instance, a time tracking tool line item might have a type that includes the following choices:
'Dev' and 'QA' might be both billable to a client, where 'Research' is not.
The django-rest-framework
serializer field specified in drf_fields.py
currently requires the user specify a table for the lookup, and if the model field is optional the user must also provide allow_null=True
and required=False
on the serializer field. This should be determined automatically by inspecting the model field.
There should be a simple way for consumers to:
LookupTable
instance and retrieve all values for that tableThe default permission class should probably be is_staff
to manage table values and any to read values, so rest_framework.permissions.IsStaffOrReadOnly
.
Right now the .lookuptable
property is lazy-loaded to prevent Django model queries to the DBMS prior to Django being fully-loaded. The implementation is trivial but:
.get_lookuptableitem_choices()
This should be replaced with something more pythonic.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.