Revised the accounting_sample command to try to use the user with the log in ID as the current system user when there are more than one users in the accounting application.
This commit is contained in:
parent
731d867c56
commit
03ebe62eb8
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
import datetime
|
import datetime
|
||||||
|
import getpass
|
||||||
import random
|
import random
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
@ -75,8 +76,14 @@ class Command(BaseCommand):
|
|||||||
elif user_model.objects.count() == 1:
|
elif user_model.objects.count() == 1:
|
||||||
user = user_model.objects.first()
|
user = user_model.objects.first()
|
||||||
else:
|
else:
|
||||||
|
try:
|
||||||
|
user = user_model.objects.get(**{
|
||||||
|
user_model.USERNAME_FIELD: getpass.getuser()
|
||||||
|
})
|
||||||
|
except ObjectDoesNotExist:
|
||||||
error = "Please specify the user with -u."
|
error = "Please specify the user with -u."
|
||||||
raise CommandError(error, returncode=1)
|
raise CommandError(error, returncode=1)
|
||||||
|
self.stdout.write(F"Filling sample data as \"{user}\"")
|
||||||
|
|
||||||
with transaction.atomic():
|
with transaction.atomic():
|
||||||
self._filler = DataFiller(user)
|
self._filler = DataFiller(user)
|
||||||
|
Loading…
Reference in New Issue
Block a user