There are two things about get_NEXT/PREVIOUS_by_DATEFIELD() which I'm
not sure if a bug should be filled agains (almost sure anyway).
given a simple model like:
class TestModel(models.Model):
date = models.DateTimeField(auto_now_add=True)
m = TestModel()
m.get_previous_by_date()
Will fail with an exception which says "Cannot use None as a query",
maybe that error could be a bit more self-explicative, like "Cannot
query next/previous items without being saved".
Which brings up the other issue, when previous/next is called the
resulting query that Django will use includes two filters: WHERE (date <
self.date) OR (date < self.date AND id < self.id). I don't get the
reason for the second filter, but this makes next/prev unusable with
unsaved objects.
Is this second filter really required? Or could it be either:
* Removed
* Added only when the object has an id
In any case, the error when using both function on unsaved objects could
be a bit more explicative. I'll fill tickets and provide patches
according to your comments, so please, comment :)
Thanks,
Marc
--
http://www.marcfargas.com -- will be finished some day.
Hi,
There are two things about get_NEXT/PREVIOUS_by_DATEFIELD() which I'm
not sure if a bug should be filled agains (almost sure anyway).
given a simple model like:
class TestModel(models.Model):
date = models.DateTimeField(auto_now_add=True)
m = TestModel()
m.get_previous_by_date()
Will fail with an exception which says "Cannot use None as a query",
maybe that error could be a bit more self-explicative, like "Cannot
query next/previous items without being saved".
Which brings up the other issue, when previous/next is called the
resulting query that Django will use includes two filters: WHERE (date <
self.date) OR (date < self.date AND id < self.id). I don't get the
reason for the second filter, but this makes next/prev unusable with
unsaved objects.
Is this second filter really required? Or could it be either:
* Removed
* Added only when the object has an id
In any case, the error when using both function on unsaved objects could
be a bit more explicative. I'll fill tickets and provide patches
according to your comments, so please, comment :)
Agreed, please create a ticket for this.
Gary
> I agree the error message could be better.
>
Thanks for the elaborate and concise answer, I'll work on a nicer error
message then ;)
Should the error raise a ProgrammingError or ValueError ?