Skip to content

Commit dca7242

Browse files
authored
Merge pull request #89 from silverlogic/baseapp-auth-add-phonenumber-field
baseapp-auth: add phone_number field to User model
2 parents ddc04d0 + eb37650 commit dca7242

File tree

10 files changed

+104
-4
lines changed

10 files changed

+104
-4
lines changed

baseapp-auth/baseapp_auth/admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class AbstractUserAdmin(UserAdmin):
4242
),
4343
},
4444
),
45-
(_("Profile"), {"fields": (("first_name", "last_name"),)}),
45+
(_("Profile"), {"fields": (("first_name", "last_name", "phone_number"),)}),
4646
)
4747
add_fieldsets = (
4848
(
@@ -66,7 +66,7 @@ class AbstractUserAdmin(UserAdmin):
6666
"is_password_expired",
6767
)
6868
list_filter = ("date_joined", "is_superuser", "is_active")
69-
search_fields = ("first_name", "last_name", "email")
69+
search_fields = ("first_name", "last_name", "email", "phone_number")
7070
ordering = ("id",)
7171
filter_horizontal = ()
7272
actions = ["force_expire_password"]

baseapp-auth/baseapp_auth/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.utils import timezone
77
from django.utils.translation import gettext_lazy as _
88
from model_utils.models import TimeStampedModel
9+
from phonenumber_field.modelfields import PhoneNumberField
910

1011
from .managers import UserManager
1112

@@ -28,6 +29,7 @@ class AbstractUser(PermissionsMixin, AbstractBaseUser):
2829
# Profile
2930
first_name = models.CharField(max_length=100, blank=True)
3031
last_name = models.CharField(max_length=100, blank=True)
32+
phone_number = PhoneNumberField(blank=True, null=True, unique=True)
3133

3234
is_active = models.BooleanField(
3335
_("active"),

baseapp-auth/baseapp_auth/rest_framework/users/serializers.py

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class Meta:
3535
"avatar",
3636
"first_name",
3737
"last_name",
38+
"phone_number",
3839
)
3940
private_fields = (
4041
"email",

baseapp-auth/baseapp_auth/tests/integration/test_users.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ def test_object_keys_for_own_user(self, user_client):
5656
"avatar",
5757
"first_name",
5858
"last_name",
59+
"phone_number",
5960
}
6061
actual = set(r.data.keys())
6162
assert expected == actual
@@ -64,7 +65,7 @@ def test_object_keys_for_other_user(self, user_client):
6465
user = UserFactory()
6566
r = user_client.get(self.reverse(kwargs={"pk": user.pk}))
6667
h.responseOk(r)
67-
expected = {"id", "avatar", "first_name", "last_name"}
68+
expected = {"id", "avatar", "first_name", "last_name", "phone_number"}
6869
actual = set(r.data.keys())
6970
assert expected == actual
7071

baseapp-auth/setup.cfg

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = baseapp_auth
3-
version = 0.2.6
3+
version = 0.2.7
44
description = BaseApp Auth
55
long_description = file: README.md
66
url = https://github.com/silverlogic/baseapp-backend
@@ -20,6 +20,7 @@ install_requires =
2020
django-constance[database] >= 2.9.1
2121
django-jinja >= 2.10.0
2222
django-model-utils >= 4.3.1
23+
django-phonenumber-field >= 7.0.2
2324
baseapp-django-trench >= 0.4.4
2425
baseapp-core >= 0.2.6
2526
djangorestframework >= 3.14.0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import phonenumber_field.modelfields
2+
from django.db import migrations
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("testapp", "0007_user_groups_user_is_staff_user_user_permissions"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="user",
14+
name="phone_number",
15+
field=phonenumber_field.modelfields.PhoneNumberField(
16+
blank=True, max_length=128, null=True, region=None, unique=True
17+
),
18+
),
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import phonenumber_field.modelfields
2+
from django.db import migrations
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("testapp", "0007_user_groups_user_is_staff_user_user_permissions"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="user",
14+
name="phone_number",
15+
field=phonenumber_field.modelfields.PhoneNumberField(
16+
blank=True, max_length=128, null=True, region=None, unique=True
17+
),
18+
),
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import phonenumber_field.modelfields
2+
from django.db import migrations
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("testapp", "0003_user_groups_user_is_staff_user_user_permissions"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="user",
14+
name="phone_number",
15+
field=phonenumber_field.modelfields.PhoneNumberField(
16+
blank=True, max_length=128, null=True, region=None, unique=True
17+
),
18+
),
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import phonenumber_field.modelfields
2+
from django.db import migrations
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("testapp", "0007_user_groups_user_is_staff_user_user_permissions"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="user",
14+
name="phone_number",
15+
field=phonenumber_field.modelfields.PhoneNumberField(
16+
blank=True, max_length=128, null=True, region=None, unique=True
17+
),
18+
),
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import phonenumber_field.modelfields
2+
from django.db import migrations
3+
4+
5+
class Migration(migrations.Migration):
6+
7+
dependencies = [
8+
("testapp", "0007_user_groups_user_is_staff_user_user_permissions"),
9+
]
10+
11+
operations = [
12+
migrations.AddField(
13+
model_name="user",
14+
name="phone_number",
15+
field=phonenumber_field.modelfields.PhoneNumberField(
16+
blank=True, max_length=128, null=True, region=None, unique=True
17+
),
18+
),
19+
]

0 commit comments

Comments
 (0)