Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering models from third-party apps #528

Open
egor83 opened this issue Apr 12, 2023 · 1 comment
Open

Registering models from third-party apps #528

egor83 opened this issue Apr 12, 2023 · 1 comment

Comments

@egor83
Copy link

egor83 commented Apr 12, 2023

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
Copy link
Author

egor83 commented Apr 12, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant