Я пытался удалить объект этой модели, но получаю эту ошибку:
Field 'id' expected a number but got 'deleted template'
Я пытался удалить объект со стороны администратора (подумав это проблема с моим взглядом) , но ошибка остается прежней.
модели
class TransactionalTemplate(models.Model):
name = models.CharField(_('name'), max_length=30)
role = models.ForeignKey(Group, on_delete=models.CASCADE, verbose_name=_('role'))
content = models.TextField(_('body'))
category= models.CharField(_('category'), max_length=10, choices=CATEGORIES)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse('mail_and_sms:template_list')
def get_role(self):
return self.role
просмотров
class TemplateDeleteView(DeleteView):
model = TransactionalTemplate
template_name = 'template_confirm_delete.html'
success_message = _('was sucessfully deleted')
def delete(self, request, *args, **kwargs):
messages.success(request, f'{self.get_object()} {self.success_message}')
self.get_object().delete()
return redirect('mail_and_sms:template_list')
РЕДАКТИРОВАТЬ
Ниже приведена трассировка
Отслеживание:
Traceback (most recent call last):
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 1772, in get_prep_value
return int(value)
The above exception (invalid literal for int() with base 10: 'deleted template') was the direct cause of the following exception:
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/views/generic/base.py", line 71, in view
return self.dispatch(request, *args, **kwargs)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/utils/decorators.py", line 43, in _wrapper
return bound_method(*args, **kwargs)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/contrib/auth/decorators.py", line 21, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/home/abdoul/Desktop/DevWork/c/mail_and_sms/views.py", line 75, in dispatch
return super(TemplateDeleteView, self).dispatch(request, *args, **kwargs)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch
return handler(request, *args, **kwargs)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/views/generic/edit.py", line 218, in post
return self.delete(request, *args, **kwargs)
File "/home/abdoul/Desktop/DevWork/c/mail_and_sms/views.py", line 67, in delete
self.get_object().delete()
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/base.py", line 938, in delete
return collector.delete()
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/deletion.py", line 322, in delete
{field.name: value}, self.using)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/sql/subqueries.py", line 107, in update_batch
self.get_compiler(using).execute_sql(NO_RESULTS)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1492, in execute_sql
cursor = super().execute_sql(result_type)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1131, in execute_sql
sql, params = self.as_sql()
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/sql/compiler.py", line 1458, in as_sql
val = field.get_db_prep_save(val, connection=self.connection)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/fields/related.py", line 939, in get_db_prep_save
return self.target_field.get_db_prep_save(value, connection=connection)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 821, in get_db_prep_save
return self.get_db_prep_value(value, connection=connection, prepared=False)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 2365, in get_db_prep_value
value = self.get_prep_value(value)
File "/home/abdoul/Desktop/DevWork/c_env/lib/python3.7/site-packages/django/db/models/fields/__init__.py", line 1776, in get_prep_value
) from e
Exception Type: ValueError at /app/mailandsms/template/delete/9/
Exception Value: Field 'id' expected a number but got 'deleted template'.
Любая помощь приветствуется.
Спасибо.