Задать вопрос

Тел: +7 965 3737 888





ActiveManager: filter objects depending on publication and/or expiration dates

<p>This manager is intended for use with models with publication and/or expiration dates. Objects will be retrieved only if their publication and/or expiration dates are within the current date.</p>
<p>Use is very simple:</p>
class ExampleModel(models.Model):
    publish_date = models.DateTimeField()
    expire_date = models.DateTimeField(blank=True, null=True)

    objects = models.Manager()
    actives = ActiveManager(from_date='publish_date', to_date='expire_date')

ExampleModel.actives.all() # retrieve active objects according to the current date

<p>The manager works correctly with nullable date fields. A null publication date means "<em>always published (until expiration date)</em>" and a null expiration date means "<em>never expires</em>".</p>
<p>Most models should define the objects manager as the default manager, because otherwise out of date objects won't appear in the admin app.</p>

Вопрос полезен? Да0/Нет0