Didn't forget to add this time. Thanks merge conflict, actually useful.
This commit is contained in:
parent
df9066e066
commit
409ad95c05
0
nerdshope/__init__.py
Normal file
0
nerdshope/__init__.py
Normal file
8
nerdshope/admin.py
Normal file
8
nerdshope/admin.py
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
from django.contrib import admin
|
||||||
|
|
||||||
|
# Register your models here.
|
||||||
|
|
||||||
|
from .models import BankAccount,Payment,OffDate
|
||||||
|
admin.site.register(BankAccount)
|
||||||
|
admin.site.register(Payment)
|
||||||
|
admin.site.register(OffDate)
|
6
nerdshope/apps.py
Normal file
6
nerdshope/apps.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
class NerdshopeConfig(AppConfig):
|
||||||
|
default_auto_field = 'django.db.models.BigAutoField'
|
||||||
|
name = 'nerdshope'
|
30
nerdshope/models.py
Normal file
30
nerdshope/models.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
from django.db import models
|
||||||
|
from django.utils.timezone import now
|
||||||
|
|
||||||
|
# Create your models here.
|
||||||
|
class BankAccount(models.Model):
|
||||||
|
name=models.CharField(max_length=100)
|
||||||
|
physical=models.CharField(max_length=100)
|
||||||
|
currency=models.CharField(max_length=5)
|
||||||
|
@property
|
||||||
|
def balance(self): return sum(map(Payment.objects.filter(account=self)))
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.name)+', '+str(self.balance)
|
||||||
|
|
||||||
|
class Payment(models.Model):
|
||||||
|
timestamp=models.DateTimeField(default=now)
|
||||||
|
other_party=models.CharField(max_length=100)
|
||||||
|
account=models.ForeignKey(BankAccount, on_delete=models.CASCADE)
|
||||||
|
amount=models.IntegerField(default=0)
|
||||||
|
reason=models.CharField(max_length=200)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(self.timestamp)+', '+str(self.amount)+', '+str(self.reason)
|
||||||
|
|
||||||
|
class OffDate(models.Model):
|
||||||
|
when=models.DateField(default=now)
|
||||||
|
reason=models.CharField(max_length=50,default="Hall unavailable")
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return str(str.when)+': '+str(self.reason)
|
3
nerdshope/tests.py
Normal file
3
nerdshope/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
from django.test import TestCase
|
||||||
|
|
||||||
|
# Create your tests here.
|
6
nerdshope/urls.py
Normal file
6
nerdshope/urls.py
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
from django.urls import include, path
|
||||||
|
from . import views
|
||||||
|
|
||||||
|
urlpatterns = [
|
||||||
|
path('',views.nerdshope,name='shop'),
|
||||||
|
]
|
16
nerdshope/views.py
Normal file
16
nerdshope/views.py
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
from django.shortcuts import render
|
||||||
|
from rakka.utils import rerender
|
||||||
|
from . import models
|
||||||
|
from main.models import Update
|
||||||
|
|
||||||
|
@rerender
|
||||||
|
def nerdshope():
|
||||||
|
accounts=models.BankAccount.objects.all()
|
||||||
|
sums={curr:sum([n.balance for n in filter(lambda x:x.currency==curr,accounts)]) for curr in set(map(lambda x:x.currency,accounts))}
|
||||||
|
moneyblob='</li>\n<li>'.join([f'{k}: {v}' for k,v in sums.items()])
|
||||||
|
moneyblob='Current monetary state: <ul>\n<li>'+moneyblob+'</li>\n</ul>'
|
||||||
|
return {'title':"Nerds' Hope",'content':"Store stuff. TODOing. Will include inventory and budget. <a href='https://facebook.com/nerdshope'>FB</a><br/>\nAddress is 21 Kensington St, Glenorchy<br/>\nOff dates 2022: 29th April, 6th May, 27th May, 17th June, 24th June<br/>\n"+moneyblob,'date':Update.objects.get_or_create(page='nh_main')[0].date}
|
||||||
|
|
||||||
|
@rerender
|
||||||
|
def budget():
|
||||||
|
pass
|
Loading…
Reference in New Issue
Block a user