Skip to content

pgh_event_models returning child event models for parent model #244

Description

@miguelalvarezi

First of all, thank you for this fantastic library. It adds a lot of value to our Django projects.

When a model is tracked, the pgh_event_models attribute is added to the tracked model. This attribute is not really documented, so the following may not be an issue, but I thought I'd report it anyway in case it helps someone trying to use this property.

If I follow the example in the FAQ "How do I track models with concrete inheritance?":

@pghistory.track(
    obj_field=pghistory.ObjForeignKey(
        related_name="parent_event",
        related_query_name="parent_event_query",
    )
)
class Parent(models.Model):
    field_a = models.CharField(default="unknown")


@pghistory.track(
    obj_field=pghistory.ObjForeignKey(
        related_name="child_event",
        related_query_name="child_event_query",
    )
)
class Child(Parent):
    field_b = models.CharField(default="unknown")

When I read the pgh_event_models on the Parent model, I get the event models of the Child model:

In [2]: Parent.pgh_event_models
Out[2]: {'insert': core.models.ChildEvent, 'update': core.models.ChildEvent}

In [3]: Child.pgh_event_models
Out[3]: {'insert': core.models.ChildEvent, 'update': core.models.ChildEvent}

Nevertheless, as a library user, I haven't faced any behavioral issue so far related to this, but maybe someone more familiar with the internals of the library can figure out some potential issues when tracking model hierarchies.

Thanks again!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions