-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
created profile model enabling to add followers
- Loading branch information
1 parent
1bf00c4
commit 99e7c0a
Showing
6 changed files
with
87 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
from django.contrib import admin | ||
|
||
from .models import Profile | ||
# Register your models here. | ||
|
||
admin.site.register(Profile) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.2 on 2017-11-22 01:07 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Profile', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('activated', models.BooleanField(default=False)), | ||
('timestamp', models.DateTimeField(auto_now_add=True)), | ||
('updated', models.DateTimeField(auto_now=True)), | ||
('followers', models.ManyToManyField(blank=True, related_name='followers', to=settings.AUTH_USER_MODEL)), | ||
('following', models.ManyToManyField(blank=True, related_name='following', to=settings.AUTH_USER_MODEL)), | ||
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.2 on 2017-11-22 01:17 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('profiles', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='profile', | ||
name='following', | ||
), | ||
migrations.AlterField( | ||
model_name='profile', | ||
name='followers', | ||
field=models.ManyToManyField(blank=True, related_name='is_following', to=settings.AUTH_USER_MODEL), | ||
), | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,28 @@ | ||
from django.db import models | ||
|
||
from django.conf import settings | ||
from django.db.models.signals import post_save | ||
# Create your models here. | ||
|
||
User = settings.AUTH_USER_MODEL | ||
|
||
|
||
class Profile(models.Model): | ||
user = models.OneToOneField(User) | ||
followers = models.ManyToManyField(User, related_name='is_following', blank=True) | ||
activated = models.BooleanField(default=False) | ||
timestamp = models.DateTimeField(auto_now_add=True) | ||
updated = models.DateTimeField(auto_now=True) | ||
|
||
def __str__(self): | ||
return self.user.username | ||
|
||
|
||
def post_save_user_receiver(sender, instance, created, *args, **kwargs): | ||
if created: | ||
profile, is_created = Profile.objects.get_or_create(user=instance) | ||
default_user_profile = Profile.objects.get_or_create(user__id=1)[0] | ||
default_user_profile.followers.add(instance) | ||
profile.followers.add(default_user_profile.user) | ||
|
||
|
||
post_save.connect(post_save_user_receiver, User) |
This file contains 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