Set a related_name of wagtail_userprofile on wagtailusers.UserProfile

This prevents it from clashing with other userprofile models defined elsewhere in the project. Fixes #3025
pull/3037/merge
Matt Westcott 2016-09-29 01:03:56 +01:00
rodzic 3833b0cba8
commit f45181764b
7 zmienionych plików z 60 dodań i 2 usunięć

Wyświetl plik

@ -31,6 +31,7 @@ Changelog
* Fix: Disabled use of escape key to revert content of rich text fields, which could cause accidental data loss (Matt Westcott)
* Fix: Setting `USE_THOUSAND_SEPARATOR = True` no longer breaks the rendering of numbers in JS code for InlinePanel (Mattias Loverot, Matt Westcott)
* Fix: Images / documents pagination now preserves GET parameters (Bojan Mihelac)
* Fix: Wagtail's UserProfile model now sets a related_name of ``wagtail_userprofile`` to avoid naming collisions with other user profile models (Matt Westcott)
1.6.3 (30.09.2016)

Wyświetl plik

@ -66,6 +66,7 @@ Bug fixes
* Disabled use of escape key to revert content of rich text fields, which could cause accidental data loss (Matt Westcott)
* Setting ``USE_THOUSAND_SEPARATOR = True`` no longer breaks the rendering of numbers in JS code for InlinePanel (Mattias Loverot, Matt Westcott)
* Images / documents pagination now preserves GET parameters (Bojan Mihelac)
* Wagtail's UserProfile model now sets a related_name of ``wagtail_userprofile`` to avoid naming collisions with other user profile models (Matt Westcott)
Upgrade considerations

Wyświetl plik

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-09-28 23:49
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('tests', '0010_auto_20160823_1056'),
]
operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('favourite_colour', models.CharField(max_length=255)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]

Wyświetl plik

@ -875,3 +875,9 @@ class InlineStreamPage(Page):
FieldPanel('title', classname="full title"),
InlinePanel('sections')
]
class UserProfile(models.Model):
# Wagtail's schema must be able to coexist alongside a custom UserProfile model
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
favourite_colour = models.CharField(max_length=255)

Wyświetl plik

@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-09-28 23:49
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('wagtailusers', '0004_capitalizeverbose'),
]
operations = [
migrations.AlterField(
model_name='userprofile',
name='user',
field=models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='wagtail_userprofile', to=settings.AUTH_USER_MODEL),
),
]

Wyświetl plik

@ -8,7 +8,9 @@ from django.utils.translation import ugettext_lazy as _
@python_2_unicode_compatible
class UserProfile(models.Model):
user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
user = models.OneToOneField(
settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='wagtail_userprofile'
)
submitted_notifications = models.BooleanField(
verbose_name=_('submitted notifications'),

Wyświetl plik

@ -400,7 +400,7 @@ class TestUserProfileCreation(TestCase, WagtailTestUtils):
def test_user_created_without_profile(self):
self.assertEqual(UserProfile.objects.filter(user=self.test_user).count(), 0)
with self.assertRaises(UserProfile.DoesNotExist):
self.test_user.userprofile
self.test_user.wagtail_userprofile
def test_user_profile_created_when_method_called(self):
self.assertIsInstance(UserProfile.get_for_user(self.test_user), UserProfile)