-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
704350b
commit 100a1fb
Showing
4 changed files
with
167 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,18 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import Account | ||
from .models import Transaction | ||
|
||
|
||
@admin.register(Account) | ||
class AccountAdmin(admin.ModelAdmin): | ||
list_display = ["name", "owner", "balance", "modified", "created", "is_removed"] | ||
search_fields = ["name", "owner__username"] | ||
list_filter = ["is_removed", "modified"] | ||
|
||
|
||
@admin.register(Transaction) | ||
class TransactionAdmin(admin.ModelAdmin): | ||
list_display = ["title", "account", "get_account_owner", "date", "amount"] | ||
search_fields = ["account__owner__username", "account__name", "title"] | ||
list_filter = ["account__owner", "account", "date"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
# Generated by Django 4.2.10 on 2024-03-05 12:24 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
import model_utils.fields | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Account", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"created", | ||
model_utils.fields.AutoCreatedField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="created", | ||
), | ||
), | ||
( | ||
"modified", | ||
model_utils.fields.AutoLastModifiedField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="modified", | ||
), | ||
), | ||
("is_removed", models.BooleanField(default=False)), | ||
("name", models.CharField(max_length=255)), | ||
("balance", models.FloatField(default=0.0, editable=False)), | ||
( | ||
"owner", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Account", | ||
"verbose_name_plural": "Accounts", | ||
"ordering": ["-modified", "name"], | ||
}, | ||
), | ||
migrations.CreateModel( | ||
name="Transaction", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"created", | ||
model_utils.fields.AutoCreatedField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="created", | ||
), | ||
), | ||
( | ||
"modified", | ||
model_utils.fields.AutoLastModifiedField( | ||
default=django.utils.timezone.now, | ||
editable=False, | ||
verbose_name="modified", | ||
), | ||
), | ||
("amount", models.FloatField()), | ||
("date", models.DateField(default=django.utils.timezone.now)), | ||
("title", models.CharField(max_length=127)), | ||
("description", models.TextField(blank=True)), | ||
( | ||
"account", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, to="core.account" | ||
), | ||
), | ||
], | ||
options={ | ||
"verbose_name": "Transaction", | ||
"verbose_name_plural": "Transactions", | ||
"ordering": ["date", "-modified"], | ||
}, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,39 @@ | ||
from django.db import models | ||
from django.utils import timezone | ||
from model_utils.models import SoftDeletableModel | ||
from model_utils.models import TimeStampedModel | ||
|
||
# Create your models here. | ||
from negligent_octopus.users.models import User | ||
|
||
|
||
class Account(TimeStampedModel, SoftDeletableModel): | ||
owner = models.ForeignKey(User, on_delete=models.CASCADE) | ||
name = models.CharField(max_length=255) | ||
balance = models.FloatField(default=0.0, editable=False) | ||
|
||
def __str__(self): | ||
return self.name | ||
|
||
class Meta: | ||
verbose_name = "Account" | ||
verbose_name_plural = "Accounts" | ||
ordering = ["-modified", "name"] | ||
|
||
|
||
class Transaction(TimeStampedModel): | ||
account = models.ForeignKey(Account, on_delete=models.CASCADE) | ||
amount = models.FloatField() | ||
date = models.DateField(default=timezone.now) | ||
title = models.CharField(max_length=127) | ||
description = models.TextField(blank=True) | ||
|
||
def get_account_owner(self): | ||
return str(self.account.owner) | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
class Meta: | ||
verbose_name = "Transaction" | ||
verbose_name_plural = "Transactions" | ||
ordering = ["date", "-modified"] |