Enhance make-admin to allow making superuser
This commit is contained in:
		
					parent
					
						
							
								1e68539ed8
							
						
					
				
			
			
				commit
				
					
						424ceafbb8
					
				
			
		
					 1 changed files with 6 additions and 1 deletions
				
			
		|  | @ -7,10 +7,15 @@ class Command(BaseCommand): | ||||||
| 
 | 
 | ||||||
|     def add_arguments(self, parser): |     def add_arguments(self, parser): | ||||||
|         parser.add_argument('username', type=str) |         parser.add_argument('username', type=str) | ||||||
|  |         parser.add_argument('--superuser', action='store_true') | ||||||
| 
 | 
 | ||||||
|     def handle(self, *args, **options): |     def handle(self, *args, **options): | ||||||
|         user = get_user_model().objects.get(username=options['username']) |         user = get_user_model().objects.get(username=options['username']) | ||||||
|         user.is_staff = True |         user.is_staff = True | ||||||
|  | 
 | ||||||
|  |         if options['superuser']: | ||||||
|  |             user.is_superuser = True | ||||||
|  | 
 | ||||||
|         user.save() |         user.save() | ||||||
| 
 | 
 | ||||||
|         print("{} is now admin.".format(user.username)) |         print(f"{user.username} is now admin (superuser={user.is_superuser})") | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue