justquick / django-activity-stream

Generate generic activity streams from the actions on your site. Users can follow any actors' activities for personalized streams.
http://django-activity-stream.rtfd.io/en/latest/
BSD 3-Clause "New" or "Revised" License
2.36k stars 483 forks source link

Registering models from third-party apps #528

Open egor83 opened 1 year ago

egor83 commented 1 year ago

Hello!

We wanted django-activity-stream to handle some models from third-party apps, but since it's third-party, we can't modify its apps.py/__init__.py to register them. Older version of the docs said "You normally call register right after your model is defined (models.py) but you can call it anytime before you need to generate actions or activity streams", but that was removed in the current version, so I wonder if it still applies.

(We could create a wrapper over that third-party model and register this wrapper, but working with the model itself would be more convenient.)

egor83 commented 1 year ago

We tried registering third-party model from another app's AppConfig, and it appears to be working. Still, would be nice to get a confirmation that this is the right way of doing things.

Our current code:

from django.apps import AppConfig

class MyAppConfig(AppConfig):
    name = "myapp"

    def ready(self):
        from actstream import registry
        from django_comments.models import Comment

        registry.register(self.get_model("MyModel"))
        registry.register(Comment)

It might or might not matter that myapp is below django_comments in the INSTALLED_APPS list.