Re: Custom User models

2023-11-28 Thread Okkert Joubert
Thanks Ahmed

Please tell me if I'm correct or not in saying the SchoolUser has School as
a foreign key the school will not have to be authenticated with djoser in
order to register for example or login?

On Mon, Nov 27, 2023 at 6:53 PM Ahmed Iftikhar 
wrote:

> # models.py
> from django.contrib.auth.models import AbstractUser
> from django.db import models
>
> class School(models.Model):
> # Your School model fields
>
> class SchoolUser(AbstractUser):
> school = models.ForeignKey(School, on_delete=models.CASCADE)
> # Add other custom fields as needed
> 
> # settings.py
> AUTH_USER_MODEL = 'your_app.SchoolUser'
> DJOSER = {
> 'SERIALIZERS': {
> 'user_create': 'your_app.serializers.CustomUserCreateSerializer',
> # Add other Djoser serializer configurations as needed
> },
> # Add other Djoser configurations as needed
> }
>
> 
> # serializers.py
> from django.contrib.auth import get_user_model
> from rest_framework import serializers
>
> class SchoolUserSerializer(serializers.ModelSerializer):
> class Meta:
> model = get_user_model()
> fields = '__all__'
>
> class SchoolSerializer(serializers.ModelSerializer):
> class Meta:
> model = School
> fields = '__all__'
>
> *
> at the end
> python manage.py makemigrations
> python manage.py migrate
>
> and enjoy
>
> On Mon, Nov 27, 2023 at 8:10 PM Okkert Joubert 
> wrote:
>
>> Good morning all,
>>
>> I made a custom user model for a school, it is currently working with
>> djoser authentication, now what I want to add is for the school to add
>> users, so my School model is a foreignkey in SchoolUser is this possible
>> firstly and secondly can I add the djoser authentication to the SchoolUser
>> model as well
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/2754d7b3-a54a-40d6-9cab-50c0a2dbb812n%40googlegroups.com
>> 
>> .
>>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Django users" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/django-users/zejReFcayis/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAGAxPTwxB46wZrgjeiZZop%3Dnq5Ch-4FLXL6z3UO%3DGQq_5g%3Dueg%40mail.gmail.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAK0teFN0MNzTO9JG06u0HSccmh15wRs81ECMvgOUgnYqJhGceg%40mail.gmail.com.


Re: Custom User models

2023-11-27 Thread Ahmed Iftikhar
# models.py
from django.contrib.auth.models import AbstractUser
from django.db import models

class School(models.Model):
# Your School model fields

class SchoolUser(AbstractUser):
school = models.ForeignKey(School, on_delete=models.CASCADE)
# Add other custom fields as needed

# settings.py
AUTH_USER_MODEL = 'your_app.SchoolUser'
DJOSER = {
'SERIALIZERS': {
'user_create': 'your_app.serializers.CustomUserCreateSerializer',
# Add other Djoser serializer configurations as needed
},
# Add other Djoser configurations as needed
}

# serializers.py
from django.contrib.auth import get_user_model
from rest_framework import serializers

class SchoolUserSerializer(serializers.ModelSerializer):
class Meta:
model = get_user_model()
fields = '__all__'

class SchoolSerializer(serializers.ModelSerializer):
class Meta:
model = School
fields = '__all__'
*
at the end
python manage.py makemigrations
python manage.py migrate

and enjoy

On Mon, Nov 27, 2023 at 8:10 PM Okkert Joubert 
wrote:

> Good morning all,
>
> I made a custom user model for a school, it is currently working with
> djoser authentication, now what I want to add is for the school to add
> users, so my School model is a foreignkey in SchoolUser is this possible
> firstly and secondly can I add the djoser authentication to the SchoolUser
> model as well
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2754d7b3-a54a-40d6-9cab-50c0a2dbb812n%40googlegroups.com
> 
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAGAxPTwxB46wZrgjeiZZop%3Dnq5Ch-4FLXL6z3UO%3DGQq_5g%3Dueg%40mail.gmail.com.


Re: Custom User models

2023-11-27 Thread Clive Bruton
I am taking it that there is more than one "school"? If so, surely  
it's is just a many-to-many relationship.


On 27 Nov 2023, at 09:33, Okkert Joubert wrote:


Good morning all,

I made a custom user model for a school, it is currently working  
with djoser authentication, now what I want to add is for the  
school to add users, so my School model is a foreignkey in  
SchoolUser is this possible firstly and secondly can I add the  
djoser authentication to the SchoolUser model as well


--
You received this message because you are subscribed to the Google  
Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it,  
send an email to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/ 
d/msgid/django-users/2754d7b3-a54a-40d6-9cab-50c0a2dbb812n% 
40googlegroups.com.


--
You received this message because you are subscribed to the Google Groups "Django 
users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/650A06A2-C854-4361-9BF3-5CCDF636F2D0%40indx.co.uk.


Custom User models

2023-11-27 Thread Okkert Joubert
Good morning all,

I made a custom user model for a school, it is currently working with 
djoser authentication, now what I want to add is for the school to add 
users, so my School model is a foreignkey in SchoolUser is this possible 
firstly and secondly can I add the djoser authentication to the SchoolUser 
model as well

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2754d7b3-a54a-40d6-9cab-50c0a2dbb812n%40googlegroups.com.