Add User field to models
Support for multiple users !
This commit is contained in:
parent
df2f2e4c37
commit
2ac316aaca
5 changed files with 172 additions and 27 deletions
|
@ -7,9 +7,19 @@ from django.db import models
|
|||
from django.forms import ModelForm
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
|
||||
class Category(models.Model):
|
||||
class UserModel(models.Model):
|
||||
user = models.ForeignKey(
|
||||
User, on_delete=models.CASCADE, verbose_name=_("User"), editable=False
|
||||
)
|
||||
|
||||
class Meta:
|
||||
abstract = True
|
||||
|
||||
|
||||
class Category(UserModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(
|
||||
max_length=64, default=_("Category"), verbose_name=_("Name")
|
||||
|
@ -48,7 +58,7 @@ class CategoryForm(ModelForm):
|
|||
fields = ["name", "icon", "budget"]
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
class Transaction(UserModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(
|
||||
max_length=256, default=_("Transaction"), verbose_name=_("Name")
|
||||
|
@ -121,7 +131,7 @@ def invoice_path(instance, filename):
|
|||
return pathlib.Path("invoices", str(instance.id)).with_suffix(".pdf")
|
||||
|
||||
|
||||
class Invoice(models.Model):
|
||||
class Invoice(UserModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
name = models.CharField(
|
||||
max_length=256, default=_("Invoice"), verbose_name=_("Name")
|
||||
|
@ -177,7 +187,7 @@ def snapshot_path(instance, filename):
|
|||
return pathlib.Path("snapshots", str(instance.id)).with_suffix(".pdf")
|
||||
|
||||
|
||||
class Snapshot(models.Model):
|
||||
class Snapshot(UserModel):
|
||||
id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
|
||||
date = models.DateField(default=date.today, unique=True, verbose_name=_("Date"))
|
||||
value = models.DecimalField(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue