File tree 4 files changed +30
-2
lines changed
4 files changed +30
-2
lines changed Original file line number Diff line number Diff line change
1
+ # Generated by Django 5.0.6 on 2024-07-02 01:47
2
+
3
+ from django .db import migrations , models
4
+
5
+
6
+ class Migration (migrations .Migration ):
7
+ dependencies = [
8
+ ("expenses" , "0003_merge_20240701_2317" ),
9
+ ]
10
+
11
+ operations = [
12
+ migrations .AlterField (
13
+ model_name = "expense" ,
14
+ name = "username" ,
15
+ field = models .UUIDField (),
16
+ ),
17
+ ]
Original file line number Diff line number Diff line change 8
8
9
9
class Expense (models .Model ):
10
10
id = models .AutoField (primary_key = True )
11
- username = models .ForeignKey ( settings . AUTH_USER_MODEL , on_delete = models . CASCADE , to_field = "user_id" )
11
+ username = models .UUIDField ( )
12
12
description = models .CharField (max_length = 255 , blank = True , null = True )
13
13
user_expense_type = models .ForeignKey (UserExpenseType , on_delete = models .CASCADE )
14
14
category = models .ForeignKey (Category , on_delete = models .CASCADE )
Original file line number Diff line number Diff line change 8
8
9
9
class ExpenseSerializer (serializers .Serializer ):
10
10
id = serializers .IntegerField (read_only = True )
11
- username = serializers .PrimaryKeyRelatedField ( queryset = get_user_model (). objects . all () )
11
+ username = serializers .UUIDField ( )
12
12
user_expense_type = serializers .PrimaryKeyRelatedField (queryset = UserExpenseType .objects .all (), required = False )
13
13
category = serializers .PrimaryKeyRelatedField (queryset = Category .objects .all ())
14
14
bankcard_id = serializers .PrimaryKeyRelatedField (queryset = BankCard .objects .all ())
15
15
amount = serializers .IntegerField ()
16
16
description = serializers .CharField (max_length = 255 , allow_blank = True , allow_null = True )
17
+ created_at = serializers .DateTimeField (read_only = True )
17
18
18
19
def validate (self , data ):
19
20
user_expense_type = data .get ("user_expense_type" )
Original file line number Diff line number Diff line change @@ -37,6 +37,16 @@ def list(self, request):
37
37
try :
38
38
username = get_user_id_from_token (request )
39
39
expenses = Expense .objects .filter (username = username )
40
+
41
+ start_date = request .query_params .get ("start_date" )
42
+ end_date = request .query_params .get ("end_date" )
43
+
44
+ if start_date and end_date :
45
+ expenses = expenses .filter (created_at__range = [start_date , end_date ])
46
+ elif start_date :
47
+ expenses = expenses .filter (created_at__gte = start_date )
48
+ elif end_date :
49
+ expenses = expenses .filter (created_at__lte = end_date )
40
50
serializer = ExpenseSerializer (expenses , many = True )
41
51
return Response (serializer .data )
42
52
except Expense .DoesNotExist :
You can’t perform that action at this time.
0 commit comments