diff --git a/account/api/serializers.py b/account/api/serializers.py index c050532..c45091a 100644 --- a/account/api/serializers.py +++ b/account/api/serializers.py @@ -46,6 +46,7 @@ class Meta: "optional_postal_code", "is_filled_for_fun", "result_can_be_used", + "gender", ] diff --git a/account/migrations/0011_profile_gender.py b/account/migrations/0011_profile_gender.py new file mode 100644 index 0000000..8f1dbdb --- /dev/null +++ b/account/migrations/0011_profile_gender.py @@ -0,0 +1,23 @@ +# Generated by Django 4.1.10 on 2024-02-08 12:10 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("account", "0010_rename_age_profile_year_of_birth"), + ] + + operations = [ + migrations.AddField( + model_name="profile", + name="gender", + field=models.CharField( + blank=True, + choices=[("M", "Male"), ("F", "Female"), ("X", "X")], + max_length=2, + null=True, + ), + ), + ] diff --git a/account/models.py b/account/models.py index d50254c..8f01957 100644 --- a/account/models.py +++ b/account/models.py @@ -34,6 +34,11 @@ class Meta: class Profile(models.Model): + GENDER_OPTIONS = [ + ("M", "Male"), + ("F", "Female"), + ("X", "X"), + ] user = models.OneToOneField( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="profile" ) @@ -42,6 +47,9 @@ class Profile(models.Model): optional_postal_code = models.CharField(max_length=10, null=True) is_filled_for_fun = models.BooleanField(default=False) result_can_be_used = models.BooleanField(default=True) + gender = models.CharField( + max_length=2, choices=GENDER_OPTIONS, null=True, blank=True + ) def __str__(self): return self.user.username diff --git a/account/tests/test_api.py b/account/tests/test_api.py index 03c8a72..12bef10 100644 --- a/account/tests/test_api.py +++ b/account/tests/test_api.py @@ -75,6 +75,15 @@ def test_profile_created(api_client): assert user.profile.postal_code is None +@pytest.mark.django_db +def test_profile_patch_geneder(api_client_authenticated, users, profiles): + user = users.get(username="test1") + url = reverse("account:profiles-detail", args=[user.id]) + patch(api_client_authenticated, url, {"gender": "X"}) + user.refresh_from_db() + assert user.profile.gender == "X" + + @pytest.mark.django_db def test_profile_patch_postal_code(api_client_authenticated, users, profiles): user = users.get(username="test1")