mirror of
https://github.com/django/django.git
synced 2025-07-19 17:19:12 +00:00
[1.8.x] Fixed #26387 -- Restored the functionality of the admin's raw_id_fields in list_editable.
Backport of acfaec3db5ba39de52f6e607e74343dccf72fba1 from master
This commit is contained in:
parent
540b487cd6
commit
0496838e61
@ -638,9 +638,9 @@ class ModelAdmin(BaseModelAdmin):
|
|||||||
extra = '' if settings.DEBUG else '.min'
|
extra = '' if settings.DEBUG else '.min'
|
||||||
js = [
|
js = [
|
||||||
'core.js',
|
'core.js',
|
||||||
'admin/RelatedObjectLookups.js',
|
|
||||||
'jquery%s.js' % extra,
|
'jquery%s.js' % extra,
|
||||||
'jquery.init.js'
|
'jquery.init.js',
|
||||||
|
'admin/RelatedObjectLookups.js',
|
||||||
]
|
]
|
||||||
if self.actions is not None:
|
if self.actions is not None:
|
||||||
js.append('actions%s.js' % extra)
|
js.append('actions%s.js' % extra)
|
||||||
|
@ -128,3 +128,12 @@ function dismissDeleteRelatedObjectPopup(win, objId) {
|
|||||||
// Kept for backward compatibility
|
// Kept for backward compatibility
|
||||||
showAddAnotherPopup = showRelatedObjectPopup;
|
showAddAnotherPopup = showRelatedObjectPopup;
|
||||||
dismissAddAnotherPopup = dismissAddRelatedObjectPopup;
|
dismissAddAnotherPopup = dismissAddRelatedObjectPopup;
|
||||||
|
|
||||||
|
django.jQuery(function($){
|
||||||
|
$(document).ready(function() {
|
||||||
|
$('.related-lookup').click(function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
showRelatedObjectLookupPopup(this);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -75,10 +75,6 @@
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
showAddAnotherPopup(this);
|
showAddAnotherPopup(this);
|
||||||
});
|
});
|
||||||
$('.related-lookup').click(function(e) {
|
|
||||||
e.preventDefault();
|
|
||||||
showRelatedObjectLookupPopup(this);
|
|
||||||
});
|
|
||||||
{% if adminform and add %}
|
{% if adminform and add %}
|
||||||
$('form#{{ opts.model_name }}_form :input:visible:enabled:first').focus()
|
$('form#{{ opts.model_name }}_form :input:visible:enabled:first').focus()
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -15,3 +15,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed data loss on SQLite where ``DurationField`` values with fractional
|
* Fixed data loss on SQLite where ``DurationField`` values with fractional
|
||||||
seconds could be saved as ``None`` (:ticket:`26324`).
|
seconds could be saved as ``None`` (:ticket:`26324`).
|
||||||
|
|
||||||
|
* Restored the functionality of the admin's ``raw_id_fields`` in
|
||||||
|
``list_editable`` (:ticket:`26387`).
|
||||||
|
@ -33,16 +33,17 @@ from .models import (
|
|||||||
GenRelReference, Grommet, ImplicitlyGeneratedPK, Ingredient,
|
GenRelReference, Grommet, ImplicitlyGeneratedPK, Ingredient,
|
||||||
InlineReference, InlineReferer, Inquisition, Language, Link,
|
InlineReference, InlineReferer, Inquisition, Language, Link,
|
||||||
MainPrepopulated, ModelWithStringPrimaryKey, NotReferenced, OldSubscriber,
|
MainPrepopulated, ModelWithStringPrimaryKey, NotReferenced, OldSubscriber,
|
||||||
OtherStory, Paper, Parent, ParentWithDependentChildren, Person, Persona,
|
OtherStory, Paper, Parent, ParentWithDependentChildren, ParentWithUUIDPK,
|
||||||
Picture, Pizza, Plot, PlotDetails, PlotProxy, PluggableSearchPerson,
|
Person, Persona, Picture, Pizza, Plot, PlotDetails, PlotProxy,
|
||||||
Podcast, Post, PrePopulatedPost, PrePopulatedPostLargeSlug,
|
PluggableSearchPerson, Podcast, Post, PrePopulatedPost,
|
||||||
PrePopulatedSubPost, Promo, Question, Recipe, Recommendation, Recommender,
|
PrePopulatedPostLargeSlug, PrePopulatedSubPost, Promo, Question, Recipe,
|
||||||
ReferencedByGenRel, ReferencedByInline, ReferencedByParent,
|
Recommendation, Recommender, ReferencedByGenRel, ReferencedByInline,
|
||||||
RelatedPrepopulated, Report, Reservation, Restaurant,
|
ReferencedByParent, RelatedPrepopulated, RelatedWithUUIDPKModel, Report,
|
||||||
RowLevelChangePermissionModel, Section, ShortMessage, Simple, Sketch,
|
Reservation, Restaurant, RowLevelChangePermissionModel, Section,
|
||||||
State, Story, StumpJoke, Subscriber, SuperVillain, Telegram, Thing,
|
ShortMessage, Simple, Sketch, State, Story, StumpJoke, Subscriber,
|
||||||
Topping, UnchangeableObject, UndeletableObject, UnorderedObject,
|
SuperVillain, Telegram, Thing, Topping, UnchangeableObject,
|
||||||
UserMessenger, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour,
|
UndeletableObject, UnorderedObject, UserMessenger, Villain, Vodcast,
|
||||||
|
Whatsit, Widget, Worker, WorkHour,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -989,5 +990,13 @@ site.register(Group, GroupAdmin)
|
|||||||
site2 = admin.AdminSite(name="namespaced_admin")
|
site2 = admin.AdminSite(name="namespaced_admin")
|
||||||
site2.register(User, UserAdmin)
|
site2.register(User, UserAdmin)
|
||||||
site2.register(Group, GroupAdmin)
|
site2.register(Group, GroupAdmin)
|
||||||
|
site2.register(ParentWithUUIDPK)
|
||||||
|
site2.register(
|
||||||
|
RelatedWithUUIDPKModel,
|
||||||
|
list_display=['pk', 'parent'],
|
||||||
|
list_editable=['parent'],
|
||||||
|
raw_id_fields=['parent'],
|
||||||
|
)
|
||||||
|
|
||||||
site7 = admin.AdminSite(name="admin7")
|
site7 = admin.AdminSite(name="admin7")
|
||||||
site7.register(Article, ArticleAdmin2)
|
site7.register(Article, ArticleAdmin2)
|
||||||
|
@ -4,6 +4,7 @@ from __future__ import unicode_literals
|
|||||||
import datetime
|
import datetime
|
||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
|
import uuid
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User
|
||||||
from django.contrib.contenttypes.fields import (
|
from django.contrib.contenttypes.fields import (
|
||||||
@ -909,3 +910,15 @@ class ReferencedByGenRel(models.Model):
|
|||||||
|
|
||||||
class GenRelReference(models.Model):
|
class GenRelReference(models.Model):
|
||||||
references = GenericRelation(ReferencedByGenRel)
|
references = GenericRelation(ReferencedByGenRel)
|
||||||
|
|
||||||
|
|
||||||
|
class ParentWithUUIDPK(models.Model):
|
||||||
|
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||||
|
title = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.id)
|
||||||
|
|
||||||
|
|
||||||
|
class RelatedWithUUIDPKModel(models.Model):
|
||||||
|
parent = models.ForeignKey(ParentWithUUIDPK, on_delete=models.CASCADE)
|
||||||
|
@ -51,12 +51,12 @@ from .models import (
|
|||||||
EmptyModel, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount,
|
EmptyModel, FancyDoodad, FieldOverridePost, FilteredManager, FooAccount,
|
||||||
FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language, Link,
|
FoodDelivery, FunkyTag, Gallery, Grommet, Inquisition, Language, Link,
|
||||||
MainPrepopulated, ModelWithStringPrimaryKey, OtherStory, Paper, Parent,
|
MainPrepopulated, ModelWithStringPrimaryKey, OtherStory, Paper, Parent,
|
||||||
ParentWithDependentChildren, Person, Persona, Picture, Pizza, Plot,
|
ParentWithDependentChildren, ParentWithUUIDPK, Person, Persona, Picture,
|
||||||
PlotDetails, PluggableSearchPerson, Podcast, Post, Promo, Question,
|
Pizza, Plot, PlotDetails, PluggableSearchPerson, Podcast, Post, Promo,
|
||||||
RelatedPrepopulated, Report, Restaurant, RowLevelChangePermissionModel,
|
Question, RelatedPrepopulated, RelatedWithUUIDPKModel, Report, Restaurant,
|
||||||
Section, ShortMessage, Simple, Story, Subscriber, Telegram, Topping,
|
RowLevelChangePermissionModel, Section, ShortMessage, Simple, Story,
|
||||||
UnchangeableObject, UndeletableObject, UnorderedObject, Villain, Vodcast,
|
Subscriber, Telegram, Topping, UnchangeableObject, UndeletableObject,
|
||||||
Whatsit, Widget, Worker, WorkHour,
|
UnorderedObject, Villain, Vodcast, Whatsit, Widget, Worker, WorkHour,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -4056,6 +4056,23 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase):
|
|||||||
self.assertEqual(Pizza.objects.count(), 1)
|
self.assertEqual(Pizza.objects.count(), 1)
|
||||||
self.assertEqual(Topping.objects.count(), 2)
|
self.assertEqual(Topping.objects.count(), 2)
|
||||||
|
|
||||||
|
def test_list_editable_raw_id_fields(self):
|
||||||
|
parent = ParentWithUUIDPK.objects.create(title='test')
|
||||||
|
parent2 = ParentWithUUIDPK.objects.create(title='test2')
|
||||||
|
RelatedWithUUIDPKModel.objects.create(parent=parent)
|
||||||
|
self.admin_login(username='super', password='secret', login_url=reverse('admin:index'))
|
||||||
|
change_url = reverse('admin:admin_views_relatedwithuuidpkmodel_changelist', current_app=site2.name)
|
||||||
|
self.selenium.get(self.live_server_url + change_url)
|
||||||
|
self.selenium.find_element_by_id('lookup_id_form-0-parent').click()
|
||||||
|
self.wait_for_popup()
|
||||||
|
self.selenium.switch_to.window(self.selenium.window_handles[-1])
|
||||||
|
# Select "parent2" in the popup.
|
||||||
|
self.selenium.find_element_by_link_text(str(parent2.pk)).click()
|
||||||
|
self.selenium.switch_to.window(self.selenium.window_handles[0])
|
||||||
|
# The newly selected pk should appear in the raw id input.
|
||||||
|
value = self.selenium.find_element_by_id('id_form-0-parent').get_attribute('value')
|
||||||
|
self.assertEqual(value, str(parent2.pk))
|
||||||
|
|
||||||
|
|
||||||
class SeleniumAdminViewsChromeTests(SeleniumAdminViewsFirefoxTests):
|
class SeleniumAdminViewsChromeTests(SeleniumAdminViewsFirefoxTests):
|
||||||
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
|
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user