N
N
neulwert2019-11-22 21:18:46
Django
neulwert, 2019-11-22 21:18:46

How does django detect letter case?

There is such code:
5dd824667d47a538253962.png
And here are the lines in it:

class Post(models.Model):
    STATUS_CHOICES = (
        ('draft','Draft'),
        ('published','Published')
    )

And here's how it's displayed on the admin site:
5dd824a25fba3214969518.png
Notice the status object above the "delete" button. Question: why does django capitalize draft and published? I have a guess, but I'm not sure: does it automatically detect and select the capitalized word because the sentence starts with it? Those. will there be times when django will insert this text in the middle or end of a sentence and write it in lowercase, and I need to be careful to always type in lowercase and uppercase letters?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alternativshik, 2019-11-22
@neulwert

Because in that select from ('draft','Draft'), 0 is taken as value and 1 as a label.
Similarly, post.status will always be a 0 element, and post.get_status_display() must be called to access the signature
https://docs.djangoproject.com/en/2.2/ref/models/i...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question