Add basic counter model

This commit is contained in:
Skia
2016-03-28 14:54:35 +02:00
parent 7d7652e319
commit 21f1393097
17 changed files with 132 additions and 2 deletions

0
counter/__init__.py Normal file
View File

6
counter/admin.py Normal file
View File

@ -0,0 +1,6 @@
from django.contrib import admin
from counter.models import Counter
# Register your models here.
admin.site.register(Counter)

View File

@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('club', '0004_auto_20160321_1648'),
('core', '0001_initial'),
('accounting', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Counter',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)),
('name', models.CharField(max_length=30, verbose_name='name')),
('club', models.ForeignKey(to='club.Club', related_name='counters')),
('edit_groups', models.ManyToManyField(related_name='editable_counters', to='core.Group', blank=True)),
('products', models.ManyToManyField(related_name='counters', to='accounting.Product', blank=True)),
('view_groups', models.ManyToManyField(related_name='viewable_counters', to='core.Group', blank=True)),
],
),
]

View File

22
counter/models.py Normal file
View File

@ -0,0 +1,22 @@
from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
from club.models import Club
from accounting.models import Product
from core.models import Group
class Counter(models.Model):
name = models.CharField(_('name'), max_length=30)
club = models.ForeignKey(Club, related_name="counters")
products = models.ManyToManyField(Product, related_name="counters", blank=True)
edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
def __getattribute__(self, name):
if name == "owner_group":
return Group(name=self.club.unix_name+"-board")
return object.__getattribute__(self, name)
def __str__(self):
return self.name

View File

@ -0,0 +1,11 @@
{% extends "core/base.jinja" %}
{% block content %}
<h3>Counter</h3>
<h4>{{ counter }}</h4>
<p><strong>Club: </strong> {{ counter.club }}</p>
<p><strong>Products: </strong> {{ counter.products.all() }}</p>
{% endblock %}

View File

@ -0,0 +1,21 @@
{% extends "core/base.jinja" %}
{% block title %}
Counter list
{% endblock %}
{% block content %}
{% if counter_list %}
<h3>Counter list</h3>
<ul>
{% for c in counter_list %}
<li><a href="{{ url('counter:details', counter_id=c.id) }}">{{ c }}</a></li>
{% endfor %}
</ul>
{% else %}
There is no counters in this website.
{% endif %}
{% endblock %}

3
counter/tests.py Normal file
View File

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

10
counter/urls.py Normal file
View File

@ -0,0 +1,10 @@
from django.conf.urls import url, include
from counter.views import *
urlpatterns = [
url(r'^$', CounterListView.as_view(), name='list'),
url(r'^(?P<counter_id>[0-9]+)$', CounterDetail.as_view(), name='details'),
]

15
counter/views.py Normal file
View File

@ -0,0 +1,15 @@
from django.shortcuts import render
from django.views.generic import ListView, DetailView
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin
from counter.models import Counter
# Create your views here.
class CounterListView(CanViewMixin, ListView):
model = Counter
template_name = 'counter/counter_list.jinja'
class CounterDetail(CanViewMixin, DetailView):
model = Counter
template_name = 'counter/counter_detail.jinja'
pk_url_kwarg = "counter_id"