Clean up note app

This commit is contained in:
Alexandre Iooss 2019-07-16 09:05:30 +02:00
parent a17c11cd70
commit 58d5b5a9ff
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
7 changed files with 47 additions and 33 deletions

View File

@ -0,0 +1,5 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
default_app_config = 'note.apps.NoteConfig'

View File

@ -1,7 +1,8 @@
from django.contrib import admin
from .models import NoteClub,NoteSpec,NoteUser
from .models import NoteClub, NoteSpec, NoteUser
from .models import Alias
# Register your models here.
admin.site.register(NoteClub)
admin.site.register(NoteSpec)

View File

@ -1,5 +1,11 @@
# -*- mode: python; coding: utf-8 -*-
# Copyright (C) 2018-2019 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
from django.apps import AppConfig
from django.utils.translation import gettext_lazy as _
class NoteConfig(AppConfig):
name = 'note'
verbose_name = _('note')

View File

@ -17,46 +17,52 @@ class Alias(models.Model):
"""
alias = models.TextField(
"alias",
unique = True,
blank = False,
null = False,
unique=True,
blank=False,
null=False,
)
limit = models.Q(app_label="note", model="NoteUser") | models.Q(app_label="note",model="NoteClub")
# Owner can be linked to an user note or a club note
limit = models.Q(app_label="note", model="NoteUser") | models.Q(app_label="note", model="NoteClub")
owner_id = models.PositiveIntegerField()
owner_type = models.ForeignKey(ContentType,
on_delete=models.CASCADE,
limit_choices_to=limit)
owner = GenericForeignKey('owner_type','owner_id')
owner_type = models.ForeignKey(
ContentType,
on_delete=models.CASCADE,
limit_choices_to=limit
)
owner = GenericForeignKey('owner_type', 'owner_id')
class Note(models.Model):
"""
An abstract model, use to add transactions capabilities to a user
"""
solde = models.IntegerField(
verbose_name=_('solde du compte'),
help_text=_("en centime, l' argent crédité pour cette instance")
balance = models.DecimalField(
verbose_name=_('account balance'),
help_text=_("money credited for this instance"),
decimal_places=2, # Limit to centimes
)
active = models.BooleanField(
default = True,
verbose_name=_('etat du compte')
is_active = models.BooleanField(
default=True,
verbose_name=_('is active')
)
class Meta:
abstract = True
class NoteUser(Note):
"""
A Note associated to a User
A Note associated to an User
"""
user = models.OneToOneField(
settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
)
class Meta:
verbose_name = _("One's Note")
verbose_name_plural = _("Users Note")
verbose_name = _("one's note")
verbose_name_plural = _("users note")
def __str__(self):
return self.user.get_username()
@ -72,16 +78,18 @@ class NoteSpec(Note):
- Refund
"""
account_type = models.CharField(
max_length = 2,
choices = (("CH","chèques"),
("CB","Carte Bancaire"),
("VB","Virement Bancaire"),
("CA","Cash"),
("RB","Remboursement")
max_length=2,
choices=(
("CH", "chèques"),
("CB", "Carte Bancaire"),
("VB", "Virement Bancaire"),
("CA", "Cash"),
("RB", "Remboursement")
),
unique = True
unique=True,
)
class NoteClub(Note):
#to be added
# to be added
pass

View File

@ -1,3 +0,0 @@
from django.test import TestCase
# Create your tests here.

0
note/tests/__init__.py Normal file
View File

View File

@ -1,3 +0,0 @@
from django.shortcuts import render
# Create your views here.