I've just updated my one field of a model from IntergerField to BooleanField in order to have Checkbox in my admin form but it doesn't...
Instead, It display a select list with 3 option (Unknown, Yes, No)
As mentionned in the Django admin documentation, CheckBoxInput is the default widget so it shloudl works
I try to 'force' CheckBoxInput defining a widget forms.CheckBoxInput but it doesn't works neither...
I need this field to be editable. i verifiy that this not this option that prevent default widget but it isn't.
models.py
class Profile(SafeDeleteModel):
_safedelete_policy = SOFT_DELETE_CASCADE
pro_ide = models.AutoField(primary_key = True)
user = models.OneToOneField(User, on_delete = models.CASCADE)
site = models.ForeignKey(Site, on_delete = models.CASCADE)
...
pro_mai = models.BooleanField("Send user login/password? (y/n)",default=0, null=True, blank=True)
...
admin.py
class ProfileFormAdmin(forms.ModelForm):
FONCTIONS = Thesaurus.options_list(5,'fr')
pro_mai = forms.BooleanField(label="Envoyer le mot de passe ? (Oui/Non)",required=False)
pro_fon = forms.ChoiceField(label="Fonction", widget = forms.Select, choices = FONCTIONS)
def send_login_password(modeladmin, request, queryset):
queryset.update(
pro_mai = 1,
)
send_login_password.short_description = 'Envoyer login et mot de passe à l\'utilisateur'
class ProfileAdmin(SimpleHistoryAdmin):
list_display = ('name','contact','pro_mai','fonction',)
list_editable = ('pro_mai',)
exclude = ('pro_con','pro_lis_ran', 'pro_lis_rea', 'pro_lis_unb','pro_tel')
search_fields = ['name']
actions = [send_login_password]
form = ProfileFormAdmin
Aucun commentaire:
Enregistrer un commentaire