Opened 6 years ago

Last modified 6 years ago

#29156 new New feature

Enhance the model methods added when Meta.order_with_respect_to is used

Reported by: César García Tapia Owned by: nobody
Component: Database layer (models, ORM) Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Someday/Maybe
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

With order_with_respect_to, we can do something like this:

class Book(models.Model):
    pass

class Chapter(models.Model):
    book = models.ForeignKey(Book, on_delete=models.CASCADE)

    class Meta:
        order_with_respect_to = 'book'

It would be very nice to add some obvious features to this feature, for example:

  • book.get_chapter_order() returns the IDs of the chapters. Why not the chapter objects itself?
  • Given a chapter, we can get the next and the previous chapters, but we can't easily get that chapter's order.
  • It would be very nice to be able to add a chapter directly in a specific position, pretty much like python's insert. For example: book.insert_chapter(chapter, 3)

I know it's a very broad request, but, if you guys like the idea, I'd love to take a look if I can add the functions myself (one at a time, to get your approval on each of them).

Change History (1)

comment:1 by Tim Graham, 6 years ago

Summary: Increase 'order_with_respect_to' featuresEnhance the model methods added when Meta.order_with_respect_to is used
Triage Stage: UnreviewedSomeday/Maybe

Ideally, a ticket should propose one feature rather than several. I'm not sure what complexity might be involved in these issues, but I guess we could evaluate a patch.

Note: See TracTickets for help on using tickets.
Back to Top