[Answer]-'str' object has no attribute 'attname'

1👍

_get_next_or_previous_by_FIELD isn’t supposed to be something you call yourself.

The main problem you’re having is that it is expecting a Field object, not a string, hence the error. This is because the method is actually used as part of a curried function that is created by the field class itself, which in turn is called by the model metaclass when the model is first imported.

The currying creates the actual get_next_by_foo and get_previous_by_foo methods. In fact, these are only created for Date and Datetime fields.

Note that the uncurried method name begins with an underscore, which – with the exception of Model._meta – is a good sign that you’re not supposed to be using it in your own code.

Leave a comment