11from functools import partial
2- from typing import Any , Dict , Type , Optional
2+ from typing import Any , Dict , Type
33from uuid import UUID
44
55from django .db import models
@@ -38,7 +38,8 @@ class ActiveModel(models.Model):
3838 Attributes:
3939 is_active (BooleanField): Boolean field indicating if the record is active
4040 """
41- is_active = models .BooleanField (_ ('Active' ), default = True )
41+
42+ is_active = models .BooleanField (_ ("Active" ), default = True )
4243
4344 class Meta :
4445 abstract = True
@@ -56,10 +57,11 @@ class CodeModel(models.Model):
5657 Attributes:
5758 code (CharField): Unique 8-character code automatically generated
5859 """
60+
5961 code = models .CharField (
6062 max_length = 32 ,
6163 default = generate_code ,
62- verbose_name = _ (' Model code' ),
64+ verbose_name = _ (" Model code" ),
6365 unique = True ,
6466 )
6567
@@ -85,12 +87,13 @@ def serializer(self) -> Type[ModelSerializer]:
8587 Returns:
8688 A ModelSerializer class configured for this model instance
8789 """
90+
8891 class SelfSerializer (ModelSerializer ):
8992 class Meta :
9093 pass
9194
9295 SelfSerializer .Meta .model = self
93- SelfSerializer .Meta .fields = ' __all__'
96+ SelfSerializer .Meta .fields = " __all__"
9497 return SelfSerializer
9598
9699 def serialize (self ) -> Dict [str , Any ]:
@@ -126,6 +129,7 @@ class SlugModel(BaseModel):
126129 Attributes:
127130 slug (SlugField): URL-friendly identifier field
128131 """
132+
129133 slug = models .SlugField (max_length = 16 )
130134
131135 class Meta :
@@ -143,7 +147,10 @@ class SortOrderModel(models.Model):
143147 Attributes:
144148 sort_order (PositiveIntegerField): Field for manual ordering of instances
145149 """
146- sort_order = models .PositiveIntegerField (default = 0 , blank = False , null = False , verbose_name = _ ("Sort" ))
150+
151+ sort_order = models .PositiveIntegerField (
152+ default = 0 , blank = False , null = False , verbose_name = _ ("Sort" )
153+ )
147154
148155 class Meta :
149156 abstract = True
@@ -163,12 +170,13 @@ def _get_next_sort_order(self) -> int:
163170 return self .sort_order
164171
165172 # Get the highest sort_order value from existing instances
166- last_instance = type (self ).objects .order_by (' -sort_order' ).first ()
173+ last_instance = type (self ).objects .order_by (" -sort_order" ).first ()
167174 if last_instance and last_instance .sort_order :
168175 return last_instance .sort_order + 1
169176
170177 return 1
171178
179+
172180class TimestampedModel (models .Model ):
173181 """
174182 Abstract model that adds automatic timestamp fields for creation and updates.
@@ -181,12 +189,11 @@ class TimestampedModel(models.Model):
181189 created_at (DateTimeField): Timestamp when the instance was created
182190 updated_at (DateTimeField): Timestamp when the instance was last updated
183191 """
192+
184193 created_at = models .DateTimeField (
185- db_index = True , auto_now_add = True , verbose_name = _ ('Created at' )
186- )
187- updated_at = models .DateTimeField (
188- auto_now = True , verbose_name = _ ('Updated at' )
194+ db_index = True , auto_now_add = True , verbose_name = _ ("Created at" )
189195 )
196+ updated_at = models .DateTimeField (auto_now = True , verbose_name = _ ("Updated at" ))
190197
191198 class Meta :
192199 abstract = True
@@ -203,6 +210,7 @@ class UUIDModel(BaseModel):
203210 Attributes:
204211 id (UUIDPrimaryKeyField): UUID primary key field
205212 """
213+
206214 id = UUIDPrimaryKeyField ()
207215
208216 class Meta :
0 commit comments