Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phone Number #3

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
added phoneNumber field to profile
  • Loading branch information
ParthPant committed Feb 2, 2021
commit 01f94f2cc9214c875121416074b75c43f762f6da
4 changes: 3 additions & 1 deletion accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
class ProfileAdminModel(admin.ModelAdmin):
""" Admin Model """

list_display = ["user" ,"current_level", "is_banned", "institute"]
list_display = ["user" ,"current_level", "is_banned", "institute", "phoneNumber"]

search_fields = ["user", "user.email"]

ordering = ("-current_level", "current_level_time")

class Meta:
model = Profile

Expand Down
4 changes: 3 additions & 1 deletion accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,19 @@ class SignUpForm(UserCreationForm):
"""
# Insitute Name
institute = forms.CharField(max_length=255)
phoneNumber = forms.IntegerField()

def __init__(self, *args, **kwargs):
super(SignUpForm, self).__init__(*args, **kwargs)
# Making name required
self.fields['email'].required = True
self.fields['phoneNumber'].required = True
self.fields['first_name'].required = True

class Meta:
model = User
# The fields shown in the form
fields = ('first_name', 'last_name', 'username', 'email', 'password1', 'password2', 'institute' )
fields = ('first_name', 'last_name', 'username', 'phoneNumber','email', 'password1', 'password2', 'institute' )

def clean_email(self):
email = self.cleaned_data.get('email')
Expand Down
20 changes: 20 additions & 0 deletions accounts/migrations/0005_profile_phonenumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.17 on 2021-02-02 05:02
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('accounts', '0004_profile_is_cleared'),
]

operations = [
migrations.AddField(
model_name='profile',
name='phoneNumber',
field=models.IntegerField(null=True),
),
]
3 changes: 2 additions & 1 deletion accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Profile(models.Model):

user = models.OneToOneField(User, on_delete = models.CASCADE)
institute = models.CharField(max_length=255, null=True)
phoneNumber = models.IntegerField(null=True)
current_level = models.ForeignKey(Level, default = Level.DEFAULT_LEVEL,on_delete=models.CASCADE)
current_level_time = models.DateTimeField(default=timezone.now)
is_banned = models.BooleanField(default = False)
Expand Down Expand Up @@ -41,4 +42,4 @@ def update_user_profile(sender, instance, created, **kwargs):
"""
if created:
Profile.objects.create(user=instance)
instance.profile.save()
instance.profile.save()
3 changes: 2 additions & 1 deletion accounts/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def register(request):
user = form.save()
user.refresh_from_db() # load the profile instance created by the signal
user.profile.institute = form.cleaned_data.get('institute')
user.profile.phoneNumber = form.cleaned_data.get('phoneNumber')
user.save()
raw_password = form.cleaned_data.get('password1')
user = authenticate(username=user.username, password=raw_password)
Expand Down Expand Up @@ -59,4 +60,4 @@ def home(request):
return render(request, 'home.html')

def rules(request):
return render(request, 'rules.html')
return render(request, 'rules.html')
Binary file modified db.sqlite3
Binary file not shown.