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):
|
||||
user, _ = User.objects.get_or_create(
|
||||
email=f"staff@{DEMO_EMAIL_DOMAIN}",
|
||||
first_name="Alice",
|
||||
last_name="Schon",
|
||||
is_staff=True,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
defaults={
|
||||
"first_name": "Alice",
|
||||
"last_name": "Schon",
|
||||
"is_staff": True,
|
||||
"is_active": True,
|
||||
"is_verified": True,
|
||||
},
|
||||
)
|
||||
if _:
|
||||
user.set_password("Staff!Demo888")
|
||||
|
|
@ -116,12 +118,14 @@ class Command(BaseCommand):
|
|||
def super_user(self):
|
||||
user, _ = User.objects.get_or_create(
|
||||
email=f"super@{DEMO_EMAIL_DOMAIN}",
|
||||
first_name="Bob",
|
||||
last_name="Schon",
|
||||
is_superuser=True,
|
||||
is_staff=True,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
defaults={
|
||||
"first_name": "Bob",
|
||||
"last_name": "Schon",
|
||||
"is_superuser": True,
|
||||
"is_staff": True,
|
||||
"is_active": True,
|
||||
"is_verified": True,
|
||||
},
|
||||
)
|
||||
if _:
|
||||
user.set_password("Super!Demo888")
|
||||
|
|
|
|||
|
|
@ -107,10 +107,10 @@ class CategoryDetailSerializer(ModelSerializer):
|
|||
return list(serializer.data)
|
||||
return []
|
||||
|
||||
def get_min_price(self, obj: Category):
|
||||
def get_min_price(self, obj: Category) -> float:
|
||||
return obj.min_price
|
||||
|
||||
def get_max_price(self, obj: Category):
|
||||
def get_max_price(self, obj: Category) -> float:
|
||||
return obj.max_price
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue