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

Support for proxy models #220

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/advanced_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -272,3 +272,9 @@ Settings

``MODERATION_MODERATORS``
Tuple of moderators' email addresses to which notifications will be sent.

Using with proxy classes
--------

- Register each proxy class individually.
- Register concrete class **also** but only after registering any proxy classes under this concrete class.
4 changes: 2 additions & 2 deletions example_project/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
from django.contrib import admin
from django.contrib.auth import views as auth_views

from moderation.helpers import auto_discover
from django.utils.module_loading import autodiscover_modules

admin.autodiscover()
auto_discover()
autodiscover_modules("moderator")

handler500 # Pyflakes

Expand Down
2 changes: 1 addition & 1 deletion moderation/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def change_view(self, request, object_id, extra_context=None):
elif 'reject' in request.POST:
moderated_object.reject(request.user, reason)

content_type = ContentType.objects.get_for_model(changed_obj.__class__)
content_type = ContentType.objects.get_for_model(changed_obj.__class__, for_concrete_model=False)
try:
object_admin_url = reverse(
"admin:%s_%s_change" % (content_type.app_label, content_type.model),
Expand Down
2 changes: 1 addition & 1 deletion moderation/filterspecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def _registered_content_types():
registered = list(moderation._registered_models.keys())
registered.sort(key=lambda obj: obj.__name__)
for model in registered:
content_types.append(ContentType.objects.get_for_model(model))
content_types.append(ContentType.objects.get_for_model(model, for_concrete_model=False))
return content_types


Expand Down
4 changes: 2 additions & 2 deletions moderation/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ def get_for_instance(self, instance):
try:
moderated_object = self.get(
object_pk=instance.pk,
content_type=ContentType.objects.get_for_model(instance.__class__),
content_type=ContentType.objects.get_for_model(instance.__class__, for_concrete_model=False),
)
except self.model.MultipleObjectsReturned:
# Get the most recent one
moderated_object = self.filter(
object_pk=instance.pk,
content_type=ContentType.objects.get_for_model(instance.__class__),
content_type=ContentType.objects.get_for_model(instance.__class__, for_concrete_model=False),
).order_by('-updated')[0]
return moderated_object