Add Membership model to connect users to teams
This commit is contained in:
parent
f4cf1c9cda
commit
3bb829851d
3 changed files with 63 additions and 0 deletions
30
events/migrations/0005_auto_20180108_2221.py
Normal file
30
events/migrations/0005_auto_20180108_2221.py
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
# Generated by Django 2.0 on 2018-01-08 22:21
|
||||||
|
|
||||||
|
import datetime
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('events', '0004_auto_20180103_2212'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.CreateModel(
|
||||||
|
name='Member',
|
||||||
|
fields=[
|
||||||
|
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||||
|
('role', models.SmallIntegerField(choices=[(0, 'Normal'), (1, 'Moderator'), (2, 'Administrator')], db_index=True, default=0, verbose_name='Member Role')),
|
||||||
|
('joined_date', models.DateTimeField(default=datetime.datetime.now)),
|
||||||
|
('team', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.Team')),
|
||||||
|
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.UserProfile')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='team',
|
||||||
|
name='members',
|
||||||
|
field=models.ManyToManyField(blank=True, related_name='memberships', through='events.Member', to='events.UserProfile'),
|
||||||
|
),
|
||||||
|
]
|
|
@ -29,6 +29,23 @@ class Place(models.Model):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'%s, %s' % (self.name, self.city.name)
|
return u'%s, %s' % (self.name, self.city.name)
|
||||||
|
|
||||||
|
class PlaceSerializer(serializers.ModelSerializer):
|
||||||
|
city = serializers.CharField(read_only=True)
|
||||||
|
class Meta:
|
||||||
|
model = Place
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'city',
|
||||||
|
'address',
|
||||||
|
'longitude',
|
||||||
|
'latitude',
|
||||||
|
'tz',
|
||||||
|
'place_url',
|
||||||
|
'cover_img'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
name = models.CharField(max_length=150, verbose_name=_('Event Name'))
|
name = models.CharField(max_length=150, verbose_name=_('Event Name'))
|
||||||
team = models.ForeignKey(Team, on_delete=models.CASCADE)
|
team = models.ForeignKey(Team, on_delete=models.CASCADE)
|
||||||
|
|
|
@ -6,6 +6,7 @@ from django.utils.translation import ugettext_lazy as _
|
||||||
from .locale import *
|
from .locale import *
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
import datetime
|
||||||
|
|
||||||
class UserProfile(models.Model):
|
class UserProfile(models.Model):
|
||||||
" Store profile information about a user "
|
" Store profile information about a user "
|
||||||
|
@ -109,6 +110,21 @@ class Team(models.Model):
|
||||||
active = models.BooleanField(_("Active Team"), default=True)
|
active = models.BooleanField(_("Active Team"), default=True)
|
||||||
tz = models.CharField(max_length=32, verbose_name=_('Default Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False, help_text=_('The most commonly used timezone for this Team.'))
|
tz = models.CharField(max_length=32, verbose_name=_('Default Timezone'), default='UTC', choices=[(tz, tz) for tz in pytz.all_timezones], blank=False, null=False, help_text=_('The most commonly used timezone for this Team.'))
|
||||||
|
|
||||||
|
members = models.ManyToManyField(UserProfile, through='Member', related_name="memberships", blank=True)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return u'%s' % (self.name)
|
return u'%s' % (self.name)
|
||||||
|
|
||||||
|
class Member(models.Model):
|
||||||
|
NORMAL=0
|
||||||
|
MODERATOR=1
|
||||||
|
ADMIN=2
|
||||||
|
ROLES = [
|
||||||
|
(NORMAL, _("Normal")),
|
||||||
|
(MODERATOR, _("Moderator")),
|
||||||
|
(ADMIN, _("Administrator"))
|
||||||
|
]
|
||||||
|
team = models.ForeignKey(Team, on_delete=models.CASCADE)
|
||||||
|
user = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
|
||||||
|
role = models.SmallIntegerField(_("Member Role"), choices=ROLES, default=NORMAL, db_index=True)
|
||||||
|
joined_date = models.DateTimeField(default=datetime.datetime.now)
|
||||||
|
|
Loading…
Reference in a new issue