python - How can I change field option in model automatically in Django? -
how can change model's field option in specific condition? example, want change option of is_it_question
(editable) false
via save
function.
class typefourchoice(models.model): question_choice = models.foreignkey(typefour) is_it_question = models.booleanfield(default=false) number = models.positiveintegerfield(blank=false, default=100, editable=false) word_or_words = models.charfield(default='', blank=false, max_length=20) timestamp = models.datetimefield(auto_now_add=true) def __str__(self): return "{} : {}".format(self.question_choice, self.word_or_words) def save(self, *args, **kwargs): if self.pk none , self.is_it_question: self.number = typefourchoice.objects.filter(is_it_question=true).count() + 1 ؟؟؟؟***self.is_it_question.editable = false***???? super(typefourchoice, self).save(*args, **kwargs)
you looking statements
self._meta.get_field_by_name('is_it_question')[0].editable = false
but have pay attention consequences of action, read on post.