made use of defaults in get_or_create
This commit is contained in:
parent
1049141483
commit
fa1c384d28
@ -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)
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
Reference in New Issue
Block a user