Skip to content

Commit

Permalink
Added apps for issue f-klubben#10
Browse files Browse the repository at this point in the history
The three new apps, fembers, products, and transactions were added in
this commit. Introducing the initial design and a fixture for populating
some example data.

The models should be straight forward.
  • Loading branch information
fishbacon committed Mar 3, 2015
1 parent 720690d commit 2a9eb57
Show file tree
Hide file tree
Showing 20 changed files with 437 additions and 1 deletion.
Empty file added stregsystem/fembers/__init__.py
Empty file.
15 changes: 15 additions & 0 deletions stregsystem/fembers/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from django.contrib import admin

from fembers.models import Member, List


class MemberAdmin(admin.ModelAdmin):
exclude = ('number',)


class ListAdmin(admin.ModelAdmin):
pass


admin.site.register(Member, MemberAdmin)
admin.site.register(List, ListAdmin)
47 changes: 47 additions & 0 deletions stregsystem/fembers/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='List',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('name', models.CharField(max_length=64)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Member',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('username', models.CharField(blank=True, null=True, max_length=64)),
('name', models.CharField(default='', max_length=64)),
('number', models.IntegerField()),
('join_date', models.DateTimeField(auto_now_add=True)),
('active', models.BooleanField(default=True)),
('_pin', models.CharField(verbose_name='pin', blank=True, null=True, max_length=128)),
('note', models.TextField(blank=True)),
('email', models.EmailField(max_length=75)),
('_phone_number', models.CharField(verbose_name='phone number', blank=True, max_length=16)),
],
options={
},
bases=(models.Model,),
),
migrations.AddField(
model_name='list',
name='members',
field=models.ManyToManyField(to='fembers.Member'),
preserve_default=True,
),
]
Empty file.
30 changes: 30 additions & 0 deletions stregsystem/fembers/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.db import models


class Member(models.Model):
username = models.CharField(max_length=64, null=True, blank=True)
name = models.CharField(max_length=64, default='')
number = models.IntegerField()
join_date = models.DateTimeField(auto_now_add=True)
active = models.BooleanField(default=True)
_pin = models.CharField(verbose_name="pin",
max_length=128,
blank=True,
null=True)
note = models.TextField(blank=True)
email = models.EmailField()
_phone_number = models.CharField(verbose_name="phone number",
max_length=16,
blank=True,
validators=[])

def __str__(self):
return str.format("{s.username} #{s.number} ({s.name})", s=self)


class List(models.Model):
name = models.CharField(max_length=64)
members = models.ManyToManyField(Member)

def __str__(self):
return self.name
Empty file.
Empty file.
8 changes: 8 additions & 0 deletions stregsystem/products/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.contrib import admin

from products.models import Product, PointOfSale, Listing, Tag

admin.site.register(Product)
admin.site.register(PointOfSale)
admin.site.register(Listing)
admin.site.register(Tag)
67 changes: 67 additions & 0 deletions stregsystem/products/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations


class Migration(migrations.Migration):

dependencies = [
]

operations = [
migrations.CreateModel(
name='Listing',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('_name', models.CharField(verbose_name='name', blank=True, null=True, max_length=64)),
('number', models.IntegerField()),
('price', models.IntegerField()),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='PointOfSale',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('name', models.CharField(max_length=64)),
('listings', models.ManyToManyField(to='products.Listing')),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Product',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('name', models.CharField(max_length=64)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Tag',
fields=[
('id', models.AutoField(verbose_name='ID', primary_key=True, auto_created=True, serialize=False)),
('name', models.CharField(max_length=64)),
('value', models.IntegerField(blank=True, null=True)),
],
options={
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='tag',
unique_together=set([('name', 'value')]),
),
migrations.AddField(
model_name='listing',
name='product',
field=models.ForeignKey(to='products.Product'),
preserve_default=True,
),
]
Empty file.
54 changes: 54 additions & 0 deletions stregsystem/products/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from django.db import models
from django.utils import html


class Product(models.Model):
name = models.CharField(max_length=64)

def __str__(self):
return self.name


class PointOfSale(models.Model):
name = models.CharField(max_length=64)
listings = models.ManyToManyField('Listing')

def __str__(self):
return self.name


class Listing(models.Model):
_name = models.CharField(verbose_name="name",
max_length=64,
null=True,
blank=True)
number = models.IntegerField()
price = models.IntegerField()
product = models.ForeignKey('Product')

@property
def name(self):
if self._name:
return self._name
else:
return self.product.name

@name.setter
def name(self, n):
self._name = n

def __str__(self):
name = html.strip_tags(self.name)
return str.format("{name} #{s.number} ({s.price})", name=name, s=self)


class Tag(models.Model):
name = models.CharField(max_length=64)
value = models.IntegerField(null=True, blank=True)

def __str__(self):
return self.name

class Meta:
# should ensure that we get no tag dupes
unique_together = ("name", "value")
Empty file.
8 changes: 7 additions & 1 deletion stregsystem/stregsystem/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@

THIRD_PARTY_APPS = ()

PROJECT_APPS = ()
PROJECT_APPS = (
'stregsystem',
'fembers',
'products',
'transactions',

)

INSTALLED_APPS = DJANGO_APPS + THIRD_PARTY_APPS + PROJECT_APPS

Expand Down
Empty file.
144 changes: 144 additions & 0 deletions stregsystem/test-fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
[
{
"pk": 1,
"fields": {
"_phone_number": "88885555",
"username": "Test",
"name": "Test Chesterson",
"join_date": "2015-03-02T20:59:09.849Z",
"note": "This is test, he is a happy user.",
"email": "[email protected]",
"_pin": "1234",
"active": true,
"number": 1
},
"model": "fembers.member"
},
{
"pk": 2,
"fields": {
"_phone_number": "",
"username": "undefined",
"name": "Bob Paulson",
"join_date": "2015-03-02T21:02:19.358Z",
"note": "This is Robert Paulson.\r\n\r\nWe can't talk about his organization.",
"email": "[email protected]",
"_pin": "1234",
"active": true,
"number": 2
},
"model": "fembers.member"
},
{
"pk": 1,
"fields": {
"members": [
1,
2
],
"name": "Everyone"
},
"model": "fembers.list"
},
{
"pk": 1,
"fields": {
"product": null,
"value": 9000,
"member": 1,
"name": ""
},
"model": "transactions.transaction"
},
{
"pk": 2,
"fields": {
"product": 2,
"value": -700,
"member": 1,
"name": ""
},
"model": "transactions.transaction"
},
{
"pk": 3,
"fields": {
"product": null,
"value": 0,
"member": null,
"name": "Nothing"
},
"model": "transactions.transaction"
},
{
"pk": 2,
"fields": {
"name": "Limfjordsporter"
},
"model": "products.product"
},
{
"pk": 3,
"fields": {
"name": "<h1>Fad\u00f8l (Tuborg/Classic)</h1>"
},
"model": "products.product"
},
{
"pk": 4,
"fields": {
"name": "<h1> Fad\u00f8l i personligt glas (Tuborg/Classic) </h1>"
},
"model": "products.product"
},
{
"pk": 2,
"fields": {
"listings": [
1,
2,
3
],
"name": "Foobar"
},
"model": "products.pointofsale"
},
{
"pk": 1,
"fields": {
"product": 2,
"price": 700,
"number": 14,
"_name": ""
},
"model": "products.listing"
},
{
"pk": 2,
"fields": {
"product": 3,
"price": 2100,
"number": 65,
"_name": ""
},
"model": "products.listing"
},
{
"pk": 3,
"fields": {
"product": 4,
"price": 2500,
"number": 1765,
"_name": ""
},
"model": "products.listing"
},
{
"pk": 1,
"fields": {
"value": null,
"name": "\u00d8l"
},
"model": "products.tag"
}
]
Empty file.
5 changes: 5 additions & 0 deletions stregsystem/transactions/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib import admin

from transactions.models import Transaction

admin.site.register(Transaction)
Loading

0 comments on commit 2a9eb57

Please sign in to comment.