﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
15319	_get_next_or_previous_by_FIELD populated from Meta	Alex Robbins	nobody	"Right now date field and datetime fields use contribute_to_class to add a 'get_next_by_<field name>'. If you look at the code in _get_next_or_previous_by_FIELD, it is pretty general, and should work with any field with a stable sort order.

Maybe instead of creating get_next_by_FIELD and get_previous_by_FIELD based on field type, we could create them based on a Meta attribute in the class. I'm thinking we could call the Meta attribute seekable_fields or something like that.

For instance:
{{{#!python
class Person(models.Model):
    first_name = models.CharField(max_length=255)
    last_name = models.CharField(max_length=255)

    class Meta:
        seekable_fields = ('last_name', )
}}}

The resulting person objects would have methods named 'get_next_by_last_name' and 'get_previous_by_last_name'.

I think the benefit here is that we are able to specify the fields we want to seek by, instead of only being able to use date fields.

Eventually, we could drop the contribute_to_class methods for the date field, since it is just a special case that could be handled by including the name of any date field you wanted to be able to sort by."	New feature	closed	Database layer (models, ORM)	dev	Normal	wontfix		jdunck@…	Design decision needed	0	0	0	0	0	0
