Fakultas Ilmu Komputer UI

Commit cff7e4f3 authored by Kefas Satrio Bangkit Solideantyo's avatar Kefas Satrio Bangkit Solideantyo
Browse files

[REFACTOR] change user group creation to get_or_create

parent 02d1f355
Pipeline #72308 passed with stage
in 6 minutes and 12 seconds
......@@ -18,12 +18,8 @@ class CustomUserManager(BaseUserManager):
user = self.model(email=email, **extra_fields)
user.set_password(password)
user.save()
if not Group.objects.filter(name='client').exists():
client_role = Group.objects.create(name='client')
user.groups.add(client_role)
else:
client_role = Group.objects.get(name='client')
user.groups.add(client_role)
client_role, _created = Group.objects.get_or_create(name='client')
user.groups.add(client_role)
return user
def create_superuser(self, email, password, **extra_fields):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment