Code

Opened 6 years ago

Closed 6 years ago

#6366 closed (invalid)

Meta field get_latest_by does not support fields with a - (Do get decending order)

Reported by: shabda Owned by: nobody
Component: Core (Other) Version: master
Severity: Keywords: Models, Meta
Cc: shabda.raaj@… Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by gwilson)

Model objects have a order_by method to order, which can take arguments of the form '-attribute_name' to get descending order ordering. This syntax is not supported by get_latest_by in Meta.

Code to validate this,

class FeaturedPage(models.Model):
    ordering = models.IntegerField(default = 0, unique = True)

featured_pages = FeaturedPage.objects.all().order_by('-ordering')

This works, but if you add

    class Meta:
        get_latest_by = '-ordering'

and do FeaturedPage.objects.latest(),
It raises OperationalError.

Attachments (0)

Change History (2)

comment:1 Changed 6 years ago by gwilson

  • Description modified (diff)
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

fixed formatting it ticket description.

comment:2 Changed 6 years ago by gwilson

  • Resolution set to invalid
  • Status changed from new to closed

But using get_latest_by will use descending ordering automatically, see http://www.djangoproject.com/documentation/models/get_latest/.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.