coding utf-8 from django db import models from django contrib auth mod

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from fields import AutoOneToOneField
from blog.models import Post, Comment
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female'),
)
class Permission(models.Model):
post = models.ManyToManyField(Post)
class Group(models.Model):
name = models.CharField()
img = models.ImageField()
permisssions = models.ManyToManyField(Permission, null=True)
class Profile(models.Model):
user = AutoOneToOneField(User, related_name='blog_profile', primary_key=True)
registration_key = models.CharField(max_length=40)
sex = models.CharField(max_length=1, choices=GENDER_CHOICES, null=True)
site = models.URLField(null=True)
group = models.ForeignKey(Group)
permissions = models.ManyToManyField(Permission)
def __unicode__(self):
return self.user.username
def get_absolute_url(self):
return "/profile/%s/" % self.id
def activate_user(self):
self.user.is_active = True
self.user.save()
def has_perm(self, forum_name):
perms = self.group.permissions + self.permissions
if forum_name in perms:
return True