From fa1c384d28f97b1c9d469b7ecb08ed5daa3f5477 Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Thu, 22 Nov 2012 18:47:50 +0100 Subject: [PATCH] made use of defaults in get_or_create --- openslides/participant/forms.py | 6 ++---- openslides/participant/models.py | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/openslides/participant/forms.py b/openslides/participant/forms.py index 721cf2739..a630dae26 100644 --- a/openslides/participant/forms.py +++ b/openslides/participant/forms.py @@ -28,10 +28,8 @@ class UserCreateForm(forms.ModelForm, CssClassMixin): def __init__(self, *args, **kwargs): if kwargs.get('instance', None) is None: initial = kwargs.setdefault('initial', {}) - registered, created = Group.objects.get_or_create(name__iexact='Registered') - if created: - registered.name = 'Registered' - registered.save() + registered, created = Group.objects.get_or_create( + name__iexact='Registered', defaults={'name': 'Registered'}) initial['groups'] = [registered.pk] super(UserCreateForm, self).__init__(*args, **kwargs) diff --git a/openslides/participant/models.py b/openslides/participant/models.py index 94db74084..7f2270f0f 100644 --- a/openslides/participant/models.py +++ b/openslides/participant/models.py @@ -253,9 +253,7 @@ def djangogroup_post_save(sender, instance, signal, *args, **kwargs): def user_post_save(sender, instance, *args, **kwargs): if not kwargs['created']: return - registered, created = Group.objects.get_or_create(name__iexact='Registered') - if created: - registered.name = 'Registered' - registered.save() + registered, created = Group.objects.get_or_create( + name__iexact='Registered', defaults={'name': 'Registered'}) instance.groups.add(registered) instance.save()