order by creation datetime
This commit is contained in:
parent
16acfc67f5
commit
5edcf1793d
3 changed files with 37 additions and 7 deletions
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Generated by Django 5.1.7 on 2025-05-27 09:28
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('wallet', '0006_alter_transaction_uuid'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='created_at',
|
||||||
|
field=models.DateTimeField(auto_now_add=True, db_index=True, null=True),
|
||||||
|
),
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='transaction',
|
||||||
|
name='updated_at',
|
||||||
|
field=models.DateTimeField(auto_now=True, db_index=True, null=True),
|
||||||
|
),
|
||||||
|
]
|
||||||
|
|
@ -57,8 +57,8 @@ class Transaction(models.Model):
|
||||||
payee_id = models.UUIDField()
|
payee_id = models.UUIDField()
|
||||||
payee_type = models.IntegerField(choices=TypeChoices.choices, blank=True, null=True)
|
payee_type = models.IntegerField(choices=TypeChoices.choices, blank=True, null=True)
|
||||||
state = models.IntegerField(choices=StateChoices.choices, default=StateChoices.CREATED)
|
state = models.IntegerField(choices=StateChoices.choices, default=StateChoices.CREATED)
|
||||||
created_at = models.DateTimeField(auto_now_add=True, null=True)
|
created_at = models.DateTimeField(auto_now_add=True, null=True, db_index=True)
|
||||||
updated_at = models.DateTimeField(auto_now=True, null=True)
|
updated_at = models.DateTimeField(auto_now=True, null=True, db_index=True)
|
||||||
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL, on_delete=models.PROTECT,
|
application = models.ForeignKey(oauth2_settings.APPLICATION_MODEL, on_delete=models.PROTECT,
|
||||||
related_name='transactions', null=True)
|
related_name='transactions', null=True)
|
||||||
details = models.JSONField(null=True, blank=True, default=dict)
|
details = models.JSONField(null=True, blank=True, default=dict)
|
||||||
|
|
@ -69,7 +69,8 @@ class Transaction(models.Model):
|
||||||
|
|
||||||
# objects = TransactionManager()
|
# objects = TransactionManager()
|
||||||
|
|
||||||
# class Meta:
|
class Meta:
|
||||||
|
ordering = ['-created_at']
|
||||||
# unique_together = ('application', 'detail_id',)
|
# unique_together = ('application', 'detail_id',)
|
||||||
|
|
||||||
def withdraw_from_payer_balance(self):
|
def withdraw_from_payer_balance(self):
|
||||||
|
|
@ -212,6 +213,9 @@ class Transaction(models.Model):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
def update_details(self, force_update=False):
|
def update_details(self, force_update=False):
|
||||||
|
if not isinstance(self.details, dict):
|
||||||
|
self.details = {}
|
||||||
|
self.save()
|
||||||
# detail = {'payer_name', 'payee_name', 'application_name', 'payer_avatar_url', 'payee_avatar_url', 'application_avatar_url'}
|
# detail = {'payer_name', 'payee_name', 'application_name', 'payer_avatar_url', 'payee_avatar_url', 'application_avatar_url'}
|
||||||
is_updated = False
|
is_updated = False
|
||||||
if not self.details.get('payer_name'):
|
if not self.details.get('payer_name'):
|
||||||
|
|
@ -240,10 +244,13 @@ class Transaction(models.Model):
|
||||||
|
|
||||||
if not self.details.get('application_name'):
|
if not self.details.get('application_name'):
|
||||||
application_details = get_application_details(self.application_id)
|
application_details = get_application_details(self.application_id)
|
||||||
self.details['application_name'] = application_details.name
|
try:
|
||||||
|
self.details['application_name'] = application_details.name
|
||||||
# TODO: get avatar from details
|
# TODO: get avatar from details
|
||||||
|
|
||||||
is_updated = True
|
is_updated = True
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
if is_updated:
|
if is_updated:
|
||||||
self.save()
|
self.save()
|
||||||
|
|
|
||||||
|
|
@ -188,11 +188,11 @@ class WithdrawVerify(generics.RetrieveAPIView):
|
||||||
class TransactionListView(ListView):
|
class TransactionListView(ListView):
|
||||||
model = Transaction
|
model = Transaction
|
||||||
template_name = 'wallet/transaction_list.html'
|
template_name = 'wallet/transaction_list.html'
|
||||||
ordering = ['-created_at']
|
|
||||||
|
|
||||||
def get_queryset(self):
|
def get_queryset(self):
|
||||||
user = self.request.user
|
user = self.request.user
|
||||||
return Transaction.objects.filter(Q(payee_id=user.pk) | Q(payer_id=user.pk)).all()
|
qs = super().get_queryset()
|
||||||
|
return qs.filter(Q(payee_id=user.pk) | Q(payer_id=user.pk)).all()
|
||||||
|
|
||||||
|
|
||||||
@method_decorator(login_required, name='dispatch')
|
@method_decorator(login_required, name='dispatch')
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue