django-admin2 icon indicating copy to clipboard operation
django-admin2 copied to clipboard

Customizable LogEntry model

Open pydanny opened this issue 11 years ago • 4 comments

This is just a thought, but it would be similar to how the new Django auth.User model works:

# Psuedo-code
class AbstractLogEntry(models.Model):

    action_time = models.DateTimeField(_('action time'), auto_now=True)
    user = models.ForeignKey(settings.AUTH_USER_MODEL)
    content_type = models.ForeignKey(ContentType, blank=True, null=True)
    object_id = models.TextField(_('object id'), blank=True, null=True)
    object_repr = models.CharField(_('object repr'), max_length=200)
    action_flag = models.PositiveSmallIntegerField(_('action flag'))
    change_message = models.TextField(_('change message'), blank=True)

    class Meta:
        abstract = True

    # snip all the methods and manager


def get_logentry_model():
    return settings.get("DJADMIN2_LOGENTRY_MODEL", "djadmin2.LogEntry")

if get_logentry_model() == "djadmin2.LogEntry":

    class LogEntry(AbstractLogEntry):
        pass

With this, developers can extend the LogEntry model to do whatever they want. We might even enable them to log to it from regular model saves via signals. The downside is this is a performance hit.

More thoughts:

  • Perhaps also allow for non-ORM records to be stored?
  • Perhaps a logging system or data store better for this many writes?
  • Could also work in a queueing system.

pydanny avatar Jul 18 '13 20:07 pydanny

Needs to wait until after #290 and #306 are complete.

pydanny avatar Jul 18 '13 20:07 pydanny

You might want to look at how django-oscar (https://github.com/tangentlabs/django-oscar) handles model overrides, it works pretty effectively.

AndrewIngram avatar Jul 18 '13 23:07 AndrewIngram

+1 for DJADMIN2_LOGENTRY_MODEL +1 for "Perhaps also allow for non-ORM records to be stored?"

I'm thinking.. when extending the LogEntry, sometimes I'll have to override things like ModelHistoryView, model_history.html, history.html. So, I'm just wondering if would be interesting to have some features as "extensions/plugins"? I mean, a package, so I can implement my needs and register on djangoadmin2.

It is something to consider, (worth to discuss), or am I just complicating things?

douglasmiranda avatar Jul 21 '13 18:07 douglasmiranda

Is there a way to still implement this? I know it's been quite sometime (almost a decade tbh) but has this been resolved?

nimish-kumar avatar Feb 12 '23 14:02 nimish-kumar