2015-12-18 2 views
2

Я получаю ValueError ошибки при отправке сообщений в конечную точку, поставляемой django-comments следующим образом, который я хотел бы решить: enter image description hereДжанго комментарии ValueError

Сообщения подробно будет «Попытка идти получить тип содержимого„7“ и объект PK '1' существует поднятый ValueError. Я не знаю, почему это ValueError поднимается, как в админке я могу отправлять комментарии как таковые без ошибок:

enter image description here

Обратите внимание, что «мой пользователь» является седьмой вариант в списке типов контента в раздел администрирования.

enter image description here

Функция, которая обрабатывает оконечных/комментарии/запись/в comments.py:

@csrf_protect 
@require_POST 
def post_comment(request, next=None, using=None): 
    """ 
    Post a comment. 

    HTTP POST is required. If ``POST['submit'] == "preview"`` or if there are 
    errors a preview template, ``comments/preview.html``, will be rendered. 
    """ 
    # Fill out some initial data fields from an authenticated user, if present 
    data = request.POST.copy() 
    if request.user.is_authenticated(): 
     if not data.get('name', ''): 
      data["name"] = request.user.get_full_name() or request.user.get_username() 
     if not data.get('email', ''): 
      data["email"] = request.user.email 

    # Look up the object we're trying to comment about 
    ctype = data.get("content_type") 
    object_pk = data.get("object_pk") 
    if ctype is None or object_pk is None: 
     return CommentPostBadRequest("Missing content_type or object_pk field.") 
    try: 
     model = apps.get_model(*ctype.split(".", 1)) 
     target = model._default_manager.using(using).get(pk=object_pk) 
    except TypeError: 
     return CommentPostBadRequest(
      "Invalid content_type value: %r" % escape(ctype)) 
    except AttributeError: 
     return CommentPostBadRequest(
      "The given content-type %r does not resolve to a valid model." % escape(ctype)) 
    except ObjectDoesNotExist: 
     return CommentPostBadRequest(
      "No object matching content-type %r and object PK %r exists." % (
       escape(ctype), escape(object_pk))) 
    except (ValueError, ValidationError) as e: 
     return CommentPostBadRequest(
      "Attempting go get content-type %r and object PK %r exists raised %s" % (
       escape(ctype), escape(object_pk), e.__class__.__name__)) 

2 Дополнительные поля Я, определенные в моей пользовательских комментариев модели:

class ProfileComment(Comment): 
    comment_OP_uri = models.CharField(max_length=300) 
    comment_receiver = models.CharField(max_length=300) 

Сопутствующая форма создана после the documentation:

class ProfileCommentForm(CommentForm): 
    comment_OP_uri = forms.CharField(max_length=300) 
    comment_receiver = forms.CharField(max_length=300) 

    def get_comment_model(self): 
     # Use our custom comment model instead of the default one. 
     return ProfileComment 

    def get_comment_create_data(self): 
     # Use the data of the superclass, and add in the custom field 
     data = super(ProfileComment, self).get_comment_create_data() 
     data['comment_OP_uri', 'comment_receiver'] = self.cleaned_data['comment_OP_uri', 'comment_receiver'] 
     return data 

ответ

0

решаемые изменением значения величины content_type к users.MyUser

apps.get_model требует APP_NAME и MODEL_NAME

Смежные вопросы