Implement LogEntry model
Currently, we use the LogEntry model from django.contrib.admin. However, there are some things we need to correct:
- uses a TextField for object_id which is not indexed, use an indexed CharField instead (to support ints and uuids),
- upstream model does not have generic foreign key, so we don't have any of the querying features that would provide, and has palliative code instead
- status flags API is not extensible, just make a setting and a default instead,
- could have a better insertion helper, for example, just take an object argument and figure out content_type, object_id and object_repr (with str(object)),
- encapsulates a similarely non extensible change message, not used by crudlfap which generates default overridable messages in the views
Meta code of the above: crudlfap_log.model
from django.apps import apps crudlfap_log = apps.get_app('crudlfap_log') class Entry(models.Model): content_object = content_object = GenericForeignKey('content_type', 'object_id') content_type = ForeignKey('contenttypes.ContentType') object_id = models.CharField(db_index=True, max_length=37) # uuid4 length user = ForeignKey(settings.AUTH_USER_MODEL) status = models.SmallIntegerField(choices=crudlfap_log.get_choices()) # this should get them from settings or give create, update, delete by default # change message and object repr fields can be same as in django.contrib.admin
The above should be completely automatic like in django.contrib.admin.
Considering Luke Plant's post on GFK, particularely the "Alternative 4 - multi-table inheritance" section, we could provide another model that could be extended by other models, and provide the relation from the model to the LogEntry, making it possible to have better performance if the developer really needs it.
Other ideas ?