Home > Enterprise >  BooleanField Model not showing the default False value
BooleanField Model not showing the default False value

Time:11-04

I have a model class where the variable completed_application should default to False when creating a new user (to show that the user hasn't completed an application yet). However, by default when a new user is created it doesn't show as False in Django admin but '-' instead.

models.py:

class Completed(models.Model):
    class Meta:  
        verbose_name_plural = 'Completed Application'
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    completed_application = models.BooleanField(default=False)

admin.py:

class Company(admin.StackedInline):
    model = Completed
    can_delete: False
    verbose_name_plural = 'Completed Application'


class UserAdmin(UserAdmin):
    list_display = ('username', 'first_name', 'last_name', 'email', 'company', 'completed')
    search_fields = ('username', 'email',)
    inlines = [Company]
    list_filter = ('is_active',)
    fieldsets = (
        (None, {'fields': ('username', 'password')}),
        (('Personal info'), {'fields': ('first_name', 'last_name', 'email')}),
        (('Permissions'), {
        'fields': ('is_active', 'is_staff', 'groups',),
    }),
        (('Important dates'), {'fields': ('last_login', 'date_joined')}),
)

enter image description here

enter image description here

The red arrow in the first image above points to the Users admin panel for a newly created user. The second image shows the individual user in Django admin with the custom model added to that user.

Other point to note: Checking the box and saving the user it shows True (as to be expected), but then unchecking the box and saving the user it eventually shows False and not '-'.

Could someone explain what this '-' means and how to ensure the model always shows False on creation?

CodePudding user response:

From the docs, the can_delete should be can_delete=False not can_delete:False

CodePudding user response:

I believe it is the cant_delete that is passed false, try to remove it

  • Related