mirror of
https://gitlab.crans.org/bde/nk20
synced 2024-12-23 07:52:23 +00:00
Use model polymorphism
This commit is contained in:
parent
14282427af
commit
5110d6a16b
@ -4,7 +4,7 @@
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from .models.notes import Alias, NoteClub, NoteSpecial, NoteUser
|
||||
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
|
||||
from .models.transactions import MembershipTransaction, Transaction, \
|
||||
TransactionTemplate
|
||||
|
||||
@ -26,8 +26,8 @@ class NoteClubAdmin(admin.ModelAdmin):
|
||||
list_filter = ('is_active',)
|
||||
search_fields = ['club__name']
|
||||
|
||||
# We can't change club after creation
|
||||
readonly_fields = ('club',)
|
||||
# We can't change club after creation or the balance
|
||||
readonly_fields = ('club', 'balance')
|
||||
|
||||
def has_add_permission(self, request):
|
||||
"""
|
||||
@ -62,8 +62,8 @@ class NoteUserAdmin(admin.ModelAdmin):
|
||||
date_hierarchy = 'user__date_joined'
|
||||
ordering = ['-user__date_joined']
|
||||
|
||||
# We can't change user after creation
|
||||
readonly_fields = ('user',)
|
||||
# We can't change user after creation or the balance
|
||||
readonly_fields = ('user', 'balance')
|
||||
|
||||
def has_add_permission(self, request):
|
||||
"""
|
||||
|
@ -7,17 +7,16 @@ from django.db import models
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from polymorphic.models import PolymorphicModel
|
||||
|
||||
"""
|
||||
Defines each note types
|
||||
"""
|
||||
|
||||
|
||||
class Note(models.Model):
|
||||
class Note(PolymorphicModel):
|
||||
"""
|
||||
An model, use to add transactions capabilities
|
||||
|
||||
We do not use an abstract model to simplify the transfer between two notes.
|
||||
"""
|
||||
balance = models.IntegerField(
|
||||
verbose_name=_('account balance'),
|
||||
@ -57,6 +56,9 @@ class NoteUser(Note):
|
||||
verbose_name = _("one's note")
|
||||
verbose_name_plural = _("users note")
|
||||
|
||||
def __str__(self):
|
||||
return _("%(user)s's note") % {'user': str(self.user)}
|
||||
|
||||
|
||||
class NoteClub(Note):
|
||||
"""
|
||||
|
@ -26,6 +26,7 @@ class TransactionTemplate(models.Model):
|
||||
)
|
||||
amount = models.PositiveIntegerField(
|
||||
verbose_name=_('amount'),
|
||||
help_text=_('in centimes'),
|
||||
)
|
||||
template_type = models.CharField(
|
||||
verbose_name=_('type'),
|
||||
|
@ -32,6 +32,11 @@ INSTALLED_APPS = [
|
||||
# Theme overrides Django Admin templates
|
||||
'theme',
|
||||
|
||||
# External apps
|
||||
'polymorphic',
|
||||
'guardian',
|
||||
'reversion',
|
||||
|
||||
# Django contrib
|
||||
'django.contrib.admin',
|
||||
'django.contrib.admindocs',
|
||||
@ -42,10 +47,6 @@ INSTALLED_APPS = [
|
||||
'django.contrib.messages',
|
||||
'django.contrib.staticfiles',
|
||||
|
||||
# External apps
|
||||
'guardian',
|
||||
'reversion',
|
||||
|
||||
# Note apps
|
||||
'activity',
|
||||
'member',
|
||||
@ -120,6 +121,8 @@ AUTHENTICATION_BACKENDS = (
|
||||
'guardian.backends.ObjectPermissionBackend',
|
||||
)
|
||||
|
||||
GUARDIAN_GET_CONTENT_TYPE = 'polymorphic.contrib.guardian.get_polymorphic_base_content_type'
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/2.2/topics/i18n/
|
||||
|
||||
|
@ -6,3 +6,4 @@ pytz==2019.1
|
||||
six==1.12.0
|
||||
sqlparse==0.3.0
|
||||
django-reversion==3.0.3
|
||||
django-polymorphic==2.0.3
|
Loading…
Reference in New Issue
Block a user