Ticket #8630: 8630_r8782_admin.diff

File 8630_r8782_admin.diff, 1.9 KB (added by Carl Meyer, 11 years ago)

admin.py needs to not register the Comment model if it's been replaced with a custom model

  • django/contrib/comments/admin.py

     
    22from django.conf import settings
    33from django.contrib.comments.models import Comment
    44from django.utils.translation import ugettext_lazy as _
     5from django.contrib.comments import get_model
    56
    67class CommentsAdmin(admin.ModelAdmin):
    78    fieldsets = (
     
    2122    date_hierarchy = 'submit_date'
    2223    search_fields = ('comment', 'user__username', 'user_name', 'user_email', 'user_url', 'ip_address')
    2324
    24 admin.site.register(Comment, CommentsAdmin)
     25if get_model() is Comment:
     26    admin.site.register(Comment, CommentsAdmin)
  • django/contrib/comments/__init__.py

     
    3939    return getattr(settings, 'COMMENTS_APP', 'django.contrib.comments')
    4040
    4141def get_model():
    42     from django.contrib.comments.models import Comment
    43     return Comment
     42    if get_comment_app_name() == __name__:
     43        from django.contrib.comments.models import Comment
     44        return Comment
     45    return get_comment_app().get_model()
    4446
    4547def get_form():
    46     from django.contrib.comments.forms import CommentForm
    47     return CommentForm
     48    if get_comment_app_name() == __name__:
     49        from django.contrib.comments.forms import CommentForm
     50        return CommentForm
     51    return get_comment_app().get_form()
    4852
    4953def get_form_target():
    50     return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
     54    if get_comment_app_name() == __name__:
     55        return urlresolvers.reverse("django.contrib.comments.views.comments.post_comment")
     56    return get_comment_app().get_form_target()
    5157
    5258def get_flag_url(comment):
    5359    """
Back to Top