Почему в django при удалении модели происходит ошибка TypeError: 'NoneType' object is not callable?

view.py
class LandingDeleteView(LoginRequiredMixin, View):

    def post(self, request, pk):
        landing = Landing.objects.get(id=pk)
        print('-'*90)
        print(landing, type(landing))
        landing.delete()


models.py
class Landing(BaseModel):
    """
    Лендинг привязаный к вебинару
    """
    title = models.CharField(verbose_name='Название', blank=True, null=True, max_length=250)
    owner = models.ForeignKey(User, on_delete=models.CASCADE, verbose_name='Пользователь')
    webinar = models.ForeignKey(Webinar, on_delete=models.CASCADE, verbose_name='Вебинар')
    landing_html = models.TextField(verbose_name='HTML код лендинга', blank=True, null=True)


вывод консоли
------------------------------------------------------------------------------------------
Премиум лендинг к вебинару Тестовый вебинар <class 'landing.models.Landing'>
Internal Server Error: /dashboard/lending/1/delete
Traceback (most recent call last):
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/views/generic/base.py", line 69, in view
    return self.dispatch(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/auth/mixins.py", line 52, in dispatch
    return super().dispatch(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/views/generic/base.py", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder/landing/views.py", line 62, in post
    landing.delete()
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/db/models/base.py", line 890, in delete
    collector.collect([self], keep_parents=keep_parents)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/db/models/deletion.py", line 222, in collect
    field.remote_field.on_delete(self, field, sub_objs, self.using)
TypeError: 'NoneType' object is not callable


Через админку тоже не удаляет эту запись
Internal Server Error: /admin/landing/landing/1/delete/
Traceback (most recent call last):
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/core/handlers/exception.py", line 35, in inner
    response = get_response(request)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 128, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/core/handlers/base.py", line 126, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/admin/options.py", line 574, in wrapper
    return self.admin_site.admin_view(view)(*args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/views/decorators/cache.py", line 44, in _wrapped_view_func
    response = view_func(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/admin/sites.py", line 223, in inner
    return view(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/utils/decorators.py", line 62, in _wrapper
    return bound_func(*args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/utils/decorators.py", line 142, in _wrapped_view
    response = view_func(request, *args, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/utils/decorators.py", line 58, in bound_func
    return func.__get__(self, type(self))(*args2, **kwargs2)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1713, in delete_view
    return self._delete_view(request, object_id, extra_context)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/admin/options.py", line 1737, in _delete_view
    [obj], opts, request.user, self.admin_site, using)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/admin/utils.py", line 131, in get_deleted_objects
    collector.collect(objs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/contrib/admin/utils.py", line 195, in collect
    return super().collect(objs, source_attr=source_attr, **kwargs)
  File "/Users/a1/Desktop/lessons_django/mlm_builder/mlm_builder_env/lib/python3.6/site-packages/django/db/models/deletion.py", line 222, in collect
    field.remote_field.on_delete(self, field, sub_objs, self.using)
TypeError: 'NoneType' object is not callable
  • Вопрос задан
  • 682 просмотра
Решения вопроса 1
@vintkor Автор вопроса
Всем спасибо за участие. Проблема решена. На эту модель ссылалась другая модель по ForeignKey в которой нужно было указать on_delete=models.SET_DEFAULT
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы