OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Will a dynamic list of choices in a Django model evaluate when the model is migrated or when a user tries to select a choice for a model?

  • Thread starter Thread starter DevinG
  • Start date Start date
D

DevinG

Guest

Code​


Let's say I have the following model:

Code:
class Course(models.Model):

    title = models.CharField(max_length=48)

    YEAR_CHOICES = [(r, r) for r in range(
            datetime.date.today().year-1, datetime.date.today().year+2
        )
    ]
    year = models.IntegerField(_('year'), choices=YEAR_CHOICES)

Question​


Will the datetime.date.today() statements be evaluated right when the model is migrated, or will they be evaluated whenever the user accesses a form to set the year value for the Course model?

In other words, is my YEAR_CHOICES code above frozen to when I migrated my model or will it dynamically update as the years go by?
<h1>Code</h1>
<p>Let's say I have the following model:</p>
<pre class="lang-py prettyprint-override"><code>class Course(models.Model):

title = models.CharField(max_length=48)

YEAR_CHOICES = [(r, r) for r in range(
datetime.date.today().year-1, datetime.date.today().year+2
)
]
year = models.IntegerField(_('year'), choices=YEAR_CHOICES)
</code></pre>
<h1>Question</h1>
<p>Will the <code>datetime.date.today()</code> statements be evaluated right when the model is migrated, or will they be evaluated whenever the user accesses a form to set the <code>year</code> value for the <code>Course</code> model?</p>
<p>In other words, is my <code>YEAR_CHOICES</code> code above frozen to when I migrated my model or will it dynamically update as the years go by?</p>
 

Latest posts

S
Replies
0
Views
1
Sergey Bakaev Rettley
S
Top