Skip to content
This repository has been archived by the owner on Jun 16, 2021. It is now read-only.

All Task Completed with added features #11

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ url = "https://pypi.org/simple"
verify_ssl = true

[dev-packages]
pylint = "*"
autopep8 = "*"

[packages]
certifi = "==2019.3.9"
dj-database-url = "==0.5.0"
django-heroku = "==0.3.1"
gunicorn = "==20.0.4"
pytz = "==2019.1"
sqlparse = "==0.3.0"
whitenoise = "==5.0.1"
Django = "==2.2.1"
gunicorn = "*"
django-heroku = "*"

[requires]
python_version = "3.8"
96 changes: 94 additions & 2 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions authentication/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)
14 changes: 14 additions & 0 deletions authentication/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User


class SignUpForm(UserCreationForm):
first_name = forms.CharField(max_length=100, help_text='Last Name')
last_name = forms.CharField(max_length=100, help_text='Last Name')
email = forms.EmailField(max_length=150, help_text='Email')

class Meta:
model = User
fields = ('username', 'first_name', 'last_name',
'email', 'password1', 'password2',)
27 changes: 27 additions & 0 deletions authentication/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 2.2.1 on 2020-05-01 17:04

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')),
('bio', models.TextField(blank=True, max_length=500)),
('location', models.CharField(blank=True, max_length=30)),
('birth_date', models.DateField(blank=True, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
16 changes: 16 additions & 0 deletions authentication/migrations/0002_delete_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 2.2.1 on 2020-05-01 17:30

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('authentication', '0001_initial'),
]

operations = [
migrations.DeleteModel(
name='Profile',
),
]
28 changes: 28 additions & 0 deletions authentication/migrations/0003_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 2.2.1 on 2020-05-01 18:55

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),
('authentication', '0002_delete_profile'),
]

operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(blank=True, max_length=100)),
('last_name', models.CharField(blank=True, max_length=100)),
('email', models.EmailField(max_length=150)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
16 changes: 16 additions & 0 deletions authentication/migrations/0004_delete_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 2.2.1 on 2020-05-01 19:05

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('authentication', '0003_profile'),
]

operations = [
migrations.DeleteModel(
name='Profile',
),
]
29 changes: 29 additions & 0 deletions authentication/migrations/0005_profile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 2.2.1 on 2020-05-02 08:15

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),
('authentication', '0004_delete_profile'),
]

operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('first_name', models.CharField(blank=True, max_length=100)),
('last_name', models.CharField(blank=True, max_length=100)),
('email', models.EmailField(max_length=150)),
('bio', models.TextField()),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
17 changes: 17 additions & 0 deletions authentication/migrations/0006_remove_profile_bio.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 2.2.1 on 2020-05-02 08:32

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('authentication', '0005_profile'),
]

operations = [
migrations.RemoveField(
model_name='profile',
name='bio',
),
]
20 changes: 19 additions & 1 deletion authentication/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
from django.db import models
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from django.dispatch import receiver

# Create your models here.

class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
first_name = models.CharField(max_length=100, blank=True)
last_name = models.CharField(max_length=100, blank=True)
email = models.EmailField(max_length=150)

def __str__(self):
return self.user.username


@receiver(post_save, sender=User)
def update_profile_signal(sender, instance, created, **kwargs):
if created:
Profile.objects.create(user=instance)
instance.profile.save()
Comment on lines +7 to +21
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of receiver decorator! 👍
However, one should create an extra model only if required. Here, the user model is sufficient to store these details.

Loading