1π
β
It will only run when you interpret the file for the first time. Then it will thus stick to the item it picked, as you found out.
But we can just move the logic to the constructor of the form, like:
my_placeholders = [
'The fact that...',
'I am sure that...',
'It is awesome to...',
'I wish this was...',
'I always wanted to know how...',
'The reason I am writing this is...',
]
class EntryForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['text'].widget.attrs['placeholder'] = random.choice(
my_placeholders
)
class Meta:
model = Entry
fields = ['text']
labels = {'text': ''}
widgets = {
'text': forms.Textarea(attrs={'cols': 80, 'placeholder': None})
}
Source:stackexchange.com