I cannot register an extend user model of django

36 views
Skip to first unread message

laya

unread,
Jun 26, 2019, 12:36:02 AM6/26/19
to django...@googlegroups.com

Hi

I got stuck in extending Django User Model.

 

This is my models.py:

class CustomUser(AbstractUser):
    USER_TYPE_CHOICES = ((
1, 'student'),
                        
(2, 'professor'),)
    username = models.CharField(
max_length=50, unique=True)
    user_type = models.PositiveSmallIntegerField(
choices=USER_TYPE_CHOICES, null=True)
    first_name = models.CharField(
max_length=50)
    last_name = models.CharField(
max_length=100)
    identity_no = models.PositiveIntegerField(
default=0)
    email = models.EmailField(
max_length=300,
                             
validators=[RegexValidator
                                          (
regex="^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.["r"a-zA-Z0-9-.]+$",
                                          
message='please enter the correct format')],
                             
)
    date_joined = models.DateTimeField(
'date joined', default=timezone.now)
    is_active = models.BooleanField(
default=True)
    is_admin = models.BooleanField(
default=False)
    is_staff = models.BooleanField(
default=False)


class Student(models.Model):
    user = models.OneToOneField(CustomUser
, on_delete=models.CASCADE)
    entry_year = models.PositiveIntegerField()
    student_no = models.PositiveIntegerField()

 

my serializers.py:

class CustomUserSerializer(serializers.ModelSerializer):
   
class Meta:
        model = CustomUser
        fields = (
'first_name',
                 
'last_name',
                 
'identity_no',
                 
'email')

   
def create(self, validated_data):
       
"""
            Create and return a new `Professor user` instance, given the validated data.
        """
        
return CustomUser.objects.create(**validated_data)


class StudentSignUpSerializer(serializers.ModelSerializer):
    user = CustomUserSerializer()
# using another serializer in this serializer to access into CustomUserSerializer Fields

   
class Meta:
        model = Student
        fields = (
'user',
                 
'entry_year',
                 
)

   
def create(self, validated_data):
       
"""
            Create and return a new `Professor user` instance, given the validated data.
        """
       
return Student.objects.create(**validated_data)

my Views.py


class UserViewSet(CreateAPIView):
    queryset = CustomUser.objects.all()
    serializer_class = CustomUserSerializer


class StudentSignUp(CreateAPIView):
    queryset = Student.objects.all()
    serializer_class = StudentSignUpSerializer

 

And the error is as follow:

ANIL UMARANE

unread,
Jun 26, 2019, 1:21:05 AM6/26/19
to django...@googlegroups.com
you have doing get method are post method

Regards..........
Anil.K


--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5d12f613.1c69fb81.c57b2.3d17%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

laya

unread,
Jun 26, 2019, 1:40:00 AM6/26/19
to django...@googlegroups.com

Thanks to reply me. How I should get method?

 

Sent from Mail for Windows 10

cid:16b9239d7929d9990091

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5d12f613.1c69fb81.c57b2.3d17%40mx.google.com.
For more options, visit https://groups.google.com/d/optout.

--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

Varun Kumar

unread,
Jun 26, 2019, 8:41:04 AM6/26/19
to django...@googlegroups.com
How to connect django with hbase ?

--
Reply all
Reply to author
Forward
0 new messages