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):
|
def __init__(self, *args, **kwargs):
|
||||||
if kwargs.get('instance', None) is None:
|
if kwargs.get('instance', None) is None:
|
||||||
initial = kwargs.setdefault('initial', {})
|
initial = kwargs.setdefault('initial', {})
|
||||||
registered, created = Group.objects.get_or_create(name__iexact='Registered')
|
registered, created = Group.objects.get_or_create(
|
||||||
if created:
|
name__iexact='Registered', defaults={'name': 'Registered'})
|
||||||
registered.name = 'Registered'
|
|
||||||
registered.save()
|
|
||||||
initial['groups'] = [registered.pk]
|
initial['groups'] = [registered.pk]
|
||||||
super(UserCreateForm, self).__init__(*args, **kwargs)
|
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):
|
def user_post_save(sender, instance, *args, **kwargs):
|
||||||
if not kwargs['created']:
|
if not kwargs['created']:
|
||||||
return
|
return
|
||||||
registered, created = Group.objects.get_or_create(name__iexact='Registered')
|
registered, created = Group.objects.get_or_create(
|
||||||
if created:
|
name__iexact='Registered', defaults={'name': 'Registered'})
|
||||||
registered.name = 'Registered'
|
|
||||||
registered.save()
|
|
||||||
instance.groups.add(registered)
|
instance.groups.add(registered)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
Loading…
Reference in New Issue
Block a user