refactor(core): use defaults in get_or_create and add annotations
Refactored `get_or_create` calls in `demo_data.py` to use the `defaults` parameter for cleaner code and consistency. Added type annotations for `get_min_price` and `get_max_price` in serializers for improved type safety.
This commit is contained in:
parent
c3b4637044
commit
6d24ee0c92
2 changed files with 17 additions and 13 deletions
|
|
@ -99,11 +99,13 @@ class Command(BaseCommand):
|
||||||
def staff_user(self):
|
def staff_user(self):
|
||||||
user, _ = User.objects.get_or_create(
|
user, _ = User.objects.get_or_create(
|
||||||
email=f"staff@{DEMO_EMAIL_DOMAIN}",
|
email=f"staff@{DEMO_EMAIL_DOMAIN}",
|
||||||
first_name="Alice",
|
defaults={
|
||||||
last_name="Schon",
|
"first_name": "Alice",
|
||||||
is_staff=True,
|
"last_name": "Schon",
|
||||||
is_active=True,
|
"is_staff": True,
|
||||||
is_verified=True,
|
"is_active": True,
|
||||||
|
"is_verified": True,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if _:
|
if _:
|
||||||
user.set_password("Staff!Demo888")
|
user.set_password("Staff!Demo888")
|
||||||
|
|
@ -116,12 +118,14 @@ class Command(BaseCommand):
|
||||||
def super_user(self):
|
def super_user(self):
|
||||||
user, _ = User.objects.get_or_create(
|
user, _ = User.objects.get_or_create(
|
||||||
email=f"super@{DEMO_EMAIL_DOMAIN}",
|
email=f"super@{DEMO_EMAIL_DOMAIN}",
|
||||||
first_name="Bob",
|
defaults={
|
||||||
last_name="Schon",
|
"first_name": "Bob",
|
||||||
is_superuser=True,
|
"last_name": "Schon",
|
||||||
is_staff=True,
|
"is_superuser": True,
|
||||||
is_active=True,
|
"is_staff": True,
|
||||||
is_verified=True,
|
"is_active": True,
|
||||||
|
"is_verified": True,
|
||||||
|
},
|
||||||
)
|
)
|
||||||
if _:
|
if _:
|
||||||
user.set_password("Super!Demo888")
|
user.set_password("Super!Demo888")
|
||||||
|
|
|
||||||
|
|
@ -107,10 +107,10 @@ class CategoryDetailSerializer(ModelSerializer):
|
||||||
return list(serializer.data)
|
return list(serializer.data)
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_min_price(self, obj: Category):
|
def get_min_price(self, obj: Category) -> float:
|
||||||
return obj.min_price
|
return obj.min_price
|
||||||
|
|
||||||
def get_max_price(self, obj: Category):
|
def get_max_price(self, obj: Category) -> float:
|
||||||
return obj.max_price
|
return obj.max_price
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue