A
A
Alexander2018-04-04 09:04:31
Django
Alexander, 2018-04-04 09:04:31

Why does django throw a TypeError: 'NoneType' object is not callable when deleting a model?

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)

console output
------------------------------------------------------------------------------------------
Премиум лендинг к вебинару Тестовый вебинар <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

Doesn't delete this post through the admin either.
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

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2018-04-04
@vintkor

Thank you all for your participation. Problem solved. This model was referenced by another model by ForeignKey in which it was necessary to specify on_delete=models.SET_DEFAULT

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question