Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d8b1a7bc
authored
Feb 02, 2013
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
school: relations to Person instead of User
parent
93e60807
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
247 additions
and
6 deletions
+247
-6
school/migrations/0005_auto.py
+114
-0
school/migrations/0006_auto.py
+117
-0
school/models.py
+16
-6
No files found.
school/migrations/0005_auto.py
0 → 100644
View file @
d8b1a7bc
# -*- coding: utf-8 -*-
import
datetime
from
south.db
import
db
from
south.v2
import
SchemaMigration
from
django.db
import
models
class
Migration
(
SchemaMigration
):
def
forwards
(
self
,
orm
):
# Removing M2M table for field owners on 'Group'
db
.
delete_table
(
'school_group_owners'
)
# Removing M2M table for field members on 'Group'
db
.
delete_table
(
'school_group_members'
)
# Removing M2M table for field owners on 'Course'
db
.
delete_table
(
'school_course_owners'
)
def
backwards
(
self
,
orm
):
# Adding M2M table for field owners on 'Group'
db
.
create_table
(
'school_group_owners'
,
(
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
auto_created
=
True
)),
(
'group'
,
models
.
ForeignKey
(
orm
[
'school.group'
],
null
=
False
)),
(
'user'
,
models
.
ForeignKey
(
orm
[
'auth.user'
],
null
=
False
))
))
db
.
create_unique
(
'school_group_owners'
,
[
'group_id'
,
'user_id'
])
# Adding M2M table for field members on 'Group'
db
.
create_table
(
'school_group_members'
,
(
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
auto_created
=
True
)),
(
'group'
,
models
.
ForeignKey
(
orm
[
'school.group'
],
null
=
False
)),
(
'user'
,
models
.
ForeignKey
(
orm
[
'auth.user'
],
null
=
False
))
))
db
.
create_unique
(
'school_group_members'
,
[
'group_id'
,
'user_id'
])
# Adding M2M table for field owners on 'Course'
db
.
create_table
(
'school_course_owners'
,
(
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
auto_created
=
True
)),
(
'course'
,
models
.
ForeignKey
(
orm
[
'school.course'
],
null
=
False
)),
(
'user'
,
models
.
ForeignKey
(
orm
[
'auth.user'
],
null
=
False
))
))
db
.
create_unique
(
'school_course_owners'
,
[
'course_id'
,
'user_id'
])
models
=
{
'auth.group'
:
{
'Meta'
:
{
'object_name'
:
'Group'
},
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'80'
}),
'permissions'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Permission']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
})
},
'auth.permission'
:
{
'Meta'
:
{
'ordering'
:
"('content_type__app_label', 'content_type__model', 'codename')"
,
'unique_together'
:
"(('content_type', 'codename'),)"
,
'object_name'
:
'Permission'
},
'codename'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'content_type'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['contenttypes.ContentType']"
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'50'
})
},
'auth.user'
:
{
'Meta'
:
{
'object_name'
:
'User'
},
'date_joined'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'email'
:
(
'django.db.models.fields.EmailField'
,
[],
{
'max_length'
:
'75'
,
'blank'
:
'True'
}),
'first_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'30'
,
'blank'
:
'True'
}),
'groups'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Group']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'is_active'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'True'
}),
'is_staff'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'is_superuser'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'last_login'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'last_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'30'
,
'blank'
:
'True'
}),
'password'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
}),
'user_permissions'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Permission']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
}),
'username'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'30'
})
},
'contenttypes.contenttype'
:
{
'Meta'
:
{
'ordering'
:
"('name',)"
,
'unique_together'
:
"(('app_label', 'model'),)"
,
'object_name'
:
'ContentType'
,
'db_table'
:
"'django_content_type'"
},
'app_label'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'model'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
})
},
'school.course'
:
{
'Meta'
:
{
'object_name'
:
'Course'
},
'code'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'10'
}),
'default_group'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'blank'
:
'True'
,
'related_name'
:
"'default_group_of'"
,
'null'
:
'True'
,
'to'
:
"orm['school.Group']"
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'80'
,
'null'
:
'True'
,
'blank'
:
'True'
}),
'short_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'10'
,
'null'
:
'True'
,
'blank'
:
'True'
})
},
'school.group'
:
{
'Meta'
:
{
'unique_together'
:
"(('name', 'course', 'semester'),)"
,
'object_name'
:
'Group'
},
'course'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['school.Course']"
,
'null'
:
'True'
,
'blank'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'80'
}),
'semester'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['school.Semester']"
})
},
'school.person'
:
{
'Meta'
:
{
'object_name'
:
'Person'
},
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'user'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['auth.User']"
,
'unique'
:
'True'
})
},
'school.semester'
:
{
'Meta'
:
{
'object_name'
:
'Semester'
},
'end'
:
(
'django.db.models.fields.DateField'
,
[],
{}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'20'
}),
'start'
:
(
'django.db.models.fields.DateField'
,
[],
{})
}
}
complete_apps
=
[
'school'
]
\ No newline at end of file
school/migrations/0006_auto.py
0 → 100644
View file @
d8b1a7bc
# -*- coding: utf-8 -*-
import
datetime
from
south.db
import
db
from
south.v2
import
SchemaMigration
from
django.db
import
models
class
Migration
(
SchemaMigration
):
def
forwards
(
self
,
orm
):
# Adding M2M table for field owners on 'Group'
db
.
create_table
(
'school_group_owners'
,
(
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
auto_created
=
True
)),
(
'group'
,
models
.
ForeignKey
(
orm
[
'school.group'
],
null
=
False
)),
(
'person'
,
models
.
ForeignKey
(
orm
[
'school.person'
],
null
=
False
))
))
db
.
create_unique
(
'school_group_owners'
,
[
'group_id'
,
'person_id'
])
# Adding M2M table for field members on 'Group'
db
.
create_table
(
'school_group_members'
,
(
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
auto_created
=
True
)),
(
'group'
,
models
.
ForeignKey
(
orm
[
'school.group'
],
null
=
False
)),
(
'person'
,
models
.
ForeignKey
(
orm
[
'school.person'
],
null
=
False
))
))
db
.
create_unique
(
'school_group_members'
,
[
'group_id'
,
'person_id'
])
# Adding M2M table for field owners on 'Course'
db
.
create_table
(
'school_course_owners'
,
(
(
'id'
,
models
.
AutoField
(
verbose_name
=
'ID'
,
primary_key
=
True
,
auto_created
=
True
)),
(
'course'
,
models
.
ForeignKey
(
orm
[
'school.course'
],
null
=
False
)),
(
'person'
,
models
.
ForeignKey
(
orm
[
'school.person'
],
null
=
False
))
))
db
.
create_unique
(
'school_course_owners'
,
[
'course_id'
,
'person_id'
])
def
backwards
(
self
,
orm
):
# Removing M2M table for field owners on 'Group'
db
.
delete_table
(
'school_group_owners'
)
# Removing M2M table for field members on 'Group'
db
.
delete_table
(
'school_group_members'
)
# Removing M2M table for field owners on 'Course'
db
.
delete_table
(
'school_course_owners'
)
models
=
{
'auth.group'
:
{
'Meta'
:
{
'object_name'
:
'Group'
},
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'80'
}),
'permissions'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Permission']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
})
},
'auth.permission'
:
{
'Meta'
:
{
'ordering'
:
"('content_type__app_label', 'content_type__model', 'codename')"
,
'unique_together'
:
"(('content_type', 'codename'),)"
,
'object_name'
:
'Permission'
},
'codename'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'content_type'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['contenttypes.ContentType']"
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'50'
})
},
'auth.user'
:
{
'Meta'
:
{
'object_name'
:
'User'
},
'date_joined'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'email'
:
(
'django.db.models.fields.EmailField'
,
[],
{
'max_length'
:
'75'
,
'blank'
:
'True'
}),
'first_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'30'
,
'blank'
:
'True'
}),
'groups'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Group']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'is_active'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'True'
}),
'is_staff'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'is_superuser'
:
(
'django.db.models.fields.BooleanField'
,
[],
{
'default'
:
'False'
}),
'last_login'
:
(
'django.db.models.fields.DateTimeField'
,
[],
{
'default'
:
'datetime.datetime.now'
}),
'last_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'30'
,
'blank'
:
'True'
}),
'password'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'128'
}),
'user_permissions'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'to'
:
"orm['auth.Permission']"
,
'symmetrical'
:
'False'
,
'blank'
:
'True'
}),
'username'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'30'
})
},
'contenttypes.contenttype'
:
{
'Meta'
:
{
'ordering'
:
"('name',)"
,
'unique_together'
:
"(('app_label', 'model'),)"
,
'object_name'
:
'ContentType'
,
'db_table'
:
"'django_content_type'"
},
'app_label'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'model'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'100'
})
},
'school.course'
:
{
'Meta'
:
{
'object_name'
:
'Course'
},
'code'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'10'
}),
'default_group'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'blank'
:
'True'
,
'related_name'
:
"'default_group_of'"
,
'null'
:
'True'
,
'to'
:
"orm['school.Group']"
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'80'
,
'null'
:
'True'
,
'blank'
:
'True'
}),
'owners'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'symmetrical'
:
'False'
,
'to'
:
"orm['school.Person']"
,
'null'
:
'True'
,
'blank'
:
'True'
}),
'short_name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'max_length'
:
'10'
,
'null'
:
'True'
,
'blank'
:
'True'
})
},
'school.group'
:
{
'Meta'
:
{
'unique_together'
:
"(('name', 'course', 'semester'),)"
,
'object_name'
:
'Group'
},
'course'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['school.Course']"
,
'null'
:
'True'
,
'blank'
:
'True'
}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'members'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'blank'
:
'True'
,
'related_name'
:
"'course_groups'"
,
'null'
:
'True'
,
'symmetrical'
:
'False'
,
'to'
:
"orm['school.Person']"
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'80'
}),
'owners'
:
(
'django.db.models.fields.related.ManyToManyField'
,
[],
{
'blank'
:
'True'
,
'related_name'
:
"'owned_groups'"
,
'null'
:
'True'
,
'symmetrical'
:
'False'
,
'to'
:
"orm['school.Person']"
}),
'semester'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['school.Semester']"
})
},
'school.person'
:
{
'Meta'
:
{
'object_name'
:
'Person'
},
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'user'
:
(
'django.db.models.fields.related.ForeignKey'
,
[],
{
'to'
:
"orm['auth.User']"
,
'unique'
:
'True'
})
},
'school.semester'
:
{
'Meta'
:
{
'object_name'
:
'Semester'
},
'end'
:
(
'django.db.models.fields.DateField'
,
[],
{}),
'id'
:
(
'django.db.models.fields.AutoField'
,
[],
{
'primary_key'
:
'True'
}),
'name'
:
(
'django.db.models.fields.CharField'
,
[],
{
'unique'
:
'True'
,
'max_length'
:
'20'
}),
'start'
:
(
'django.db.models.fields.DateField'
,
[],
{})
}
}
complete_apps
=
[
'school'
]
\ No newline at end of file
school/models.py
View file @
d8b1a7bc
...
...
@@ -17,8 +17,18 @@ post_save.connect(create_user_profile, sender=User)
class
Person
(
models
.
Model
):
user
=
models
.
ForeignKey
(
User
,
null
=
False
,
blank
=
False
,
unique
=
True
)
def
short_name
(
self
):
if
user
.
last_name
:
return
user
.
last_name
else
:
return
user
.
username
def
__unicode__
(
self
):
return
self
.
user
.
__unicode__
()
if
user
.
last_name
and
user
.
first_name
:
return
_
(
"
%(first)
s
%(last)
s"
%
{
'first'
:
user
.
first_name
,
'last'
:
user
.
last_name
})
else
:
return
user
.
username
class
Course
(
models
.
Model
):
code
=
models
.
CharField
(
max_length
=
10
,
unique
=
True
)
...
...
@@ -26,7 +36,7 @@ class Course(models.Model):
short_name
=
models
.
CharField
(
max_length
=
10
,
null
=
True
,
blank
=
True
)
default_group
=
models
.
ForeignKey
(
'Group'
,
null
=
True
,
blank
=
True
,
related_name
=
'default_group_of'
)
owners
=
models
.
ManyToManyField
(
User
,
blank
=
True
,
null
=
True
)
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
)
def
get_or_create_default_group
(
self
):
self
.
default_group
=
Group
(
name
=
self
.
name
,
semester
=
Semester
.
get_current
())
...
...
@@ -50,7 +60,7 @@ class Course(models.Model):
return
self
.
code
def
owner_list
(
self
):
if
self
.
owners
:
return
", "
.
join
([
u
.
last_name
if
u
.
last_name
else
u
.
username
for
u
in
self
.
owners
.
all
()])
return
", "
.
join
([
p
.
short_name
()
for
p
in
self
.
owners
.
all
()])
else
:
return
_
(
"n/a"
)
...
...
@@ -81,15 +91,15 @@ class Group(models.Model):
name
=
models
.
CharField
(
max_length
=
80
,
unique
=
True
)
course
=
models
.
ForeignKey
(
'Course'
,
null
=
True
,
blank
=
True
)
semester
=
models
.
ForeignKey
(
'Semester'
,
null
=
False
,
blank
=
False
)
owners
=
models
.
ManyToManyField
(
User
,
blank
=
True
,
null
=
True
,
related_name
=
'owned_groups'
)
members
=
models
.
ManyToManyField
(
User
,
blank
=
True
,
null
=
True
,
related_name
=
'course_groups'
)
owners
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
related_name
=
'owned_groups'
)
members
=
models
.
ManyToManyField
(
Person
,
blank
=
True
,
null
=
True
,
related_name
=
'course_groups'
)
class
Meta
:
unique_together
=
((
'name'
,
'course'
,
'semester'
,
),
)
def
owner_list
(
self
):
if
self
.
owners
:
return
", "
.
join
([
u
.
last_name
if
u
.
last_name
else
u
.
username
for
u
in
self
.
owners
.
all
()])
return
", "
.
join
([
p
.
short_name
()
for
p
in
self
.
owners
.
all
()])
else
:
return
_
(
"n/a"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment