mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #30798 -- Fixed Meta.ordering validation for pk of related fields.
Regression in 440505cb2c.
			
			
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							c7944628a1
						
					
				
				
					commit
					95a11578ce
				
			| @@ -1708,6 +1708,10 @@ class Model(metaclass=ModelBase): | |||||||
|             fld = None |             fld = None | ||||||
|             for part in field.split(LOOKUP_SEP): |             for part in field.split(LOOKUP_SEP): | ||||||
|                 try: |                 try: | ||||||
|  |                     # pk is an alias that won't be found by opts.get_field. | ||||||
|  |                     if part == 'pk': | ||||||
|  |                         fld = _cls._meta.pk | ||||||
|  |                     else: | ||||||
|                         fld = _cls._meta.get_field(part) |                         fld = _cls._meta.get_field(part) | ||||||
|                     if fld.is_relation: |                     if fld.is_relation: | ||||||
|                         _cls = fld.get_path_info()[-1].to_opts.model |                         _cls = fld.get_path_info()[-1].to_opts.model | ||||||
|   | |||||||
| @@ -844,6 +844,18 @@ class OtherModelTests(SimpleTestCase): | |||||||
|         with register_lookup(models.CharField, Lower): |         with register_lookup(models.CharField, Lower): | ||||||
|             self.assertEqual(Model.check(), []) |             self.assertEqual(Model.check(), []) | ||||||
|  |  | ||||||
|  |     def test_ordering_pointing_to_related_model_pk(self): | ||||||
|  |         class Parent(models.Model): | ||||||
|  |             pass | ||||||
|  |  | ||||||
|  |         class Child(models.Model): | ||||||
|  |             parent = models.ForeignKey(Parent, models.CASCADE) | ||||||
|  |  | ||||||
|  |             class Meta: | ||||||
|  |                 ordering = ('parent__pk',) | ||||||
|  |  | ||||||
|  |         self.assertEqual(Child.check(), []) | ||||||
|  |  | ||||||
|     def test_ordering_pointing_to_foreignkey_field(self): |     def test_ordering_pointing_to_foreignkey_field(self): | ||||||
|         class Parent(models.Model): |         class Parent(models.Model): | ||||||
|             pass |             pass | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user