Skip to content

Commit

Permalink
created profile model enabling to add followers
Browse files Browse the repository at this point in the history
  • Loading branch information
vykuntaharsha committed Nov 22, 2017
1 parent 1bf00c4 commit 99e7c0a
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 4 deletions.
Binary file modified src/db.sqlite3
Binary file not shown.
4 changes: 3 additions & 1 deletion src/profiles/admin.py
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)
31 changes: 31 additions & 0 deletions src/profiles/migrations/0001_initial.py
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)),
],
),
]
25 changes: 25 additions & 0 deletions src/profiles/migrations/0002_auto_20171122_0117.py
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),
),
]
27 changes: 26 additions & 1 deletion src/profiles/models.py
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)
4 changes: 2 additions & 2 deletions src/profiles/templates/profiles/user.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
{% block content %}
<h1>{{ user.username }}</h1>
<hr/>
<form class="form-row" method="get" action=".">
<form class="form-inline" method="get" action=".">
<input type="text" placeholder="search" name="q" value="{{ request.GET.q }}">
<button class="submit-row" type="submit" > search </button>
<button class="btn btn-primary btn-sm" type="submit" > search </button>
</form><br/>
{% if locations %}
{% for restaurant in locations %}
Expand Down

0 comments on commit 99e7c0a

Please sign in to comment.