djangosnippets.org: Latest snippets tagged with 'date-filter'https://djangosnippets.org/tags/date-filter/2008-07-01T05:31:22.869286-05:00ActiveManager: filter objects depending on publication and/or expiration dates
2008-07-01T05:31:22.869286-05:00haplohttps://djangosnippets.org/snippets/838/<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>
<pre><code>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() …</code></pre>
Freely redistributable