Created
December 11, 2012 21:19
-
-
Save bricker/4262217 to your computer and use it in GitHub Desktop.
Django Admin's Auth system, represented with Rails ActiveRecord models.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Django Admin's auth system, represented using ActiveRecord | |
module Django | |
#-------------------------- | |
# User | |
class User < ActiveRecord::Base | |
self.table_name = "auth_user" | |
has_many :django_user_permissions, class_name: "Django::UserPermission" | |
has_many :django_user_groups, class_name: "Django::UserGroup" | |
has_many :permissions, through: :django_user_permissions | |
has_many :groups, through: :django_user_groups | |
end | |
#-------------------------- | |
# Group | |
class Group < ActiveRecord::Base | |
self.table_name = "auth_group" | |
has_many :django_group_permissions, class_name: "Django::GroupPermission" | |
has_many :django_user_groups, class_name: "Django::UserGroup" | |
has_many :permissions, through: :django_group_permissions | |
has_many :users, through: :django_user_groups | |
end | |
#-------------------------- | |
# Permission | |
class Permission < ActiveRecord::Base | |
self.table_name = "auth_permission" | |
has_many :django_user_permissions, class_name: "Django::UserPermission" | |
has_many :django_group_permissions, class_name: "Django::GroupPermission" | |
has_many :users, through: :django_user_permissions | |
has_many :groups, through: :django_group_permissions | |
end | |
#-------------------------- | |
# User <-> Group | |
class UserGroup < ActiveRecord::Base | |
self.table_name = "auth_user_groups" | |
belongs_to :group, class_name: "Django::Group" | |
belongs_to :user, class_name: "Django::User" | |
end | |
#-------------------------- | |
# User <-> Permission | |
class UserPermission < ActiveRecord::Base | |
self.table_name = "auth_user_user_permissions" | |
belongs_to :permission, class_name: "Django::Permission" | |
belongs_to :user, class_name: "Django::User" | |
end | |
#-------------------------- | |
# Group <-> Permission | |
class GroupPermission < ActiveRecord::Base | |
self.table_name = "auth_group_permissions" | |
belongs_to :permission, class_name: "Django::Permission" | |
belongs_to :group, class_name: "Django::Group" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is awesome, thanks Bryan! Just wondering if you by any chance had the migrations and db/schema.rb file for this as well?
Best,
Jeff