Arkadiy Bagdasarov
Arkadiy Bagdasarov

Reputation: 85

django delete model in admin site - 'bool' object is not callable

When I try to delete a model in the admin panel, I get this error. I can not find where the problem is.

TypeError at /admin/account/cloud/1/delete/

'bool' object is not callable

django: 1.10.6

postgres: 9.5.6

OS: Ubuntu server 16.04

Model with problem:

class Cloud(models.Model):
    NAME_CHOICE = (
        ('1', '1'),
        ('2', '2'),
        ('3', '3'),
        ('4', '4')
    )
    account = models.ForeignKey(Account, verbose_name='Аккаунт')
    name = models.CharField(choices=NAME_CHOICE, verbose_name='Название', max_length=20, default=NAME_CHOICE[0][0])
    username = models.CharField(verbose_name='Пользовательское название', max_length=100, null=True, blank=True)
    active = models.BooleanField(verbose_name='Активный?', default=False)
    params = JSONField(verbose_name='Параметры', null=True, blank=True)
    delete = models.BooleanField(verbose_name='Удален?', default=False)


    def __str__(self):
        return 'ID: {}, облако: {}'.format(self.id, (self.username or '-'))

INSTALLED_APPS:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'account',
    'api',
    'cell',
    'files',

    'deploy_frontend',
    'rest_framework',
    # 'rest_framework_docs',
    'rest_framework_swagger',
]

How obj can be "bool", if obj = cloud-object?

Upvotes: 2

Views: 1598

Answers (2)

Eduardo Basílio
Eduardo Basílio

Reputation: 615

At Django 2 this problem can also occur when your foreignkey model field set on_delete=True.

swap on_delete=True for on_delete=models.CASCADE or on_delete=models.PROTECT or on_delete=models.SET_NULL or on_delete=models.SET_DEFAULT or on_delete=models.SET()

See docs

Upvotes: 2

shad0w_wa1k3r
shad0w_wa1k3r

Reputation: 13372

Because obj.delete is a BooleanField according to your model definition rather than the default delete method. You may want to give the field a different name, like is_deleted.

Upvotes: 5

Related Questions