#15319: _get_next_or_previous_by_FIELD populated from Meta
------------------------------------------+---------------------------------
 Reporter:  alexr                         |          Owner:  nobody    
   Status:  new                           |      Milestone:            
Component:  Database layer (models, ORM)  |        Version:  SVN       
 Keywords:                                |   Triage Stage:  Unreviewed
Has patch:  0                             |  
------------------------------------------+---------------------------------
 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.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/15319>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to