Django social network application - database schema
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
2
down vote
favorite
I am writing a simple social media application in Django. I would like to know whether the following model structure is correct, or how can I improve the schema to get better performance. Do I need to split the following relation into a separate model? Like in this question
Models.py
class User(AbstractBaseUser, PermissionsMixin):
"""
Custom user model with email as username
"""
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=75, blank=True, null=True)
last_name = models.CharField(max_length=75, blank=True, null=True)
date_joined = models.DateTimeField(auto_now_add=True)
date_of_birth = models.DateField(validators=[validate_dob],
blank=True, null=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
avatar = models.URLField(blank=True, null=True)
followers = models.ManyToManyField("self", blank=True,
symmetrical=False,
related_name='following')
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS =
def __str__(self):
return self.email
@property
def age(self):
current_year = datetime.datetime.today.year
return current_year - self.date_of_birth.year
def get_full_name(self):
return ' '.format(self.first_name, self.last_name)
def get_short_name(self):
return self.first_name
class Post(models.Model):
title = models.CharField(max_length=45)
description = models.CharField(max_length=144)
author = models.ForeignKey(User, on_delete=models.CASCADE)
published_on = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['published_on']
def __str__(self):
return self.title
To prepare the feed for a requested user, I would like to use the query,
u1 = User.objects.first()
posts = Post.objects.filter(author__in=u1.following.all())
python performance database django
add a comment |Â
up vote
2
down vote
favorite
I am writing a simple social media application in Django. I would like to know whether the following model structure is correct, or how can I improve the schema to get better performance. Do I need to split the following relation into a separate model? Like in this question
Models.py
class User(AbstractBaseUser, PermissionsMixin):
"""
Custom user model with email as username
"""
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=75, blank=True, null=True)
last_name = models.CharField(max_length=75, blank=True, null=True)
date_joined = models.DateTimeField(auto_now_add=True)
date_of_birth = models.DateField(validators=[validate_dob],
blank=True, null=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
avatar = models.URLField(blank=True, null=True)
followers = models.ManyToManyField("self", blank=True,
symmetrical=False,
related_name='following')
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS =
def __str__(self):
return self.email
@property
def age(self):
current_year = datetime.datetime.today.year
return current_year - self.date_of_birth.year
def get_full_name(self):
return ' '.format(self.first_name, self.last_name)
def get_short_name(self):
return self.first_name
class Post(models.Model):
title = models.CharField(max_length=45)
description = models.CharField(max_length=144)
author = models.ForeignKey(User, on_delete=models.CASCADE)
published_on = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['published_on']
def __str__(self):
return self.title
To prepare the feed for a requested user, I would like to use the query,
u1 = User.objects.first()
posts = Post.objects.filter(author__in=u1.following.all())
python performance database django
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I am writing a simple social media application in Django. I would like to know whether the following model structure is correct, or how can I improve the schema to get better performance. Do I need to split the following relation into a separate model? Like in this question
Models.py
class User(AbstractBaseUser, PermissionsMixin):
"""
Custom user model with email as username
"""
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=75, blank=True, null=True)
last_name = models.CharField(max_length=75, blank=True, null=True)
date_joined = models.DateTimeField(auto_now_add=True)
date_of_birth = models.DateField(validators=[validate_dob],
blank=True, null=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
avatar = models.URLField(blank=True, null=True)
followers = models.ManyToManyField("self", blank=True,
symmetrical=False,
related_name='following')
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS =
def __str__(self):
return self.email
@property
def age(self):
current_year = datetime.datetime.today.year
return current_year - self.date_of_birth.year
def get_full_name(self):
return ' '.format(self.first_name, self.last_name)
def get_short_name(self):
return self.first_name
class Post(models.Model):
title = models.CharField(max_length=45)
description = models.CharField(max_length=144)
author = models.ForeignKey(User, on_delete=models.CASCADE)
published_on = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['published_on']
def __str__(self):
return self.title
To prepare the feed for a requested user, I would like to use the query,
u1 = User.objects.first()
posts = Post.objects.filter(author__in=u1.following.all())
python performance database django
I am writing a simple social media application in Django. I would like to know whether the following model structure is correct, or how can I improve the schema to get better performance. Do I need to split the following relation into a separate model? Like in this question
Models.py
class User(AbstractBaseUser, PermissionsMixin):
"""
Custom user model with email as username
"""
email = models.EmailField(unique=True)
first_name = models.CharField(max_length=75, blank=True, null=True)
last_name = models.CharField(max_length=75, blank=True, null=True)
date_joined = models.DateTimeField(auto_now_add=True)
date_of_birth = models.DateField(validators=[validate_dob],
blank=True, null=True)
is_active = models.BooleanField(default=True)
is_staff = models.BooleanField(default=False)
avatar = models.URLField(blank=True, null=True)
followers = models.ManyToManyField("self", blank=True,
symmetrical=False,
related_name='following')
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS =
def __str__(self):
return self.email
@property
def age(self):
current_year = datetime.datetime.today.year
return current_year - self.date_of_birth.year
def get_full_name(self):
return ' '.format(self.first_name, self.last_name)
def get_short_name(self):
return self.first_name
class Post(models.Model):
title = models.CharField(max_length=45)
description = models.CharField(max_length=144)
author = models.ForeignKey(User, on_delete=models.CASCADE)
published_on = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ['published_on']
def __str__(self):
return self.title
To prepare the feed for a requested user, I would like to use the query,
u1 = User.objects.first()
posts = Post.objects.filter(author__in=u1.following.all())
python performance database django
asked May 22 at 12:15
Arun
1115
1115
add a comment |Â
add a comment |Â
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f194939%2fdjango-social-network-application-database-schema%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password