Dishant
JoKer
I created a custom user model using AbstractBaseUser
I want to extend this and create another user type using OneToOneField
how to do this. I tried to extend but it shows some errors
JoKer
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager,User
# Create your models here.
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female')
)
class AccountManager(BaseUserManager):
def create_user(self,email,username,phone,gender,password=None):
if not email:
raise ValueError("email is needed")
if not username:
raise ValueError("uname is needed")
if not phone:
raise ValueError("Phone is needed")
if not gender:
raise ValueError("gender is needed")
user= self.model(
email=self.normalize_email(email),
username=username,
phone=phone,
gender=gender,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self,email,username,phone,gender,password):
user=self.create_user(
email=self.normalize_email(email),
password=password,
username=username,
phone=phone,
gender=gender,
)
user.is_admin=True
user.is_staff=True
user.is_superuser=True
user.save(using=self._db)
return user
class Account(AbstractBaseUser):
ACCTYPE = (
('Student', 'Student'),
('Staff', 'Staff')
)
email=models.EmailField(verbose_name='E-mail', max_length=30, unique=True)
username=models.CharField(verbose_name='Username', max_length=30, unique=True)
last_login=models.DateTimeField(verbose_name='Last Login', auto_now=True)
phone=models.CharField(verbose_name='Phone', max_length=50)
gender= models.CharField(choices=GENDER_CHOICES, max_length=128)
acctype = models.CharField(max_length=16, choices=ACCTYPE)
is_admin=models.BooleanField(default=False)
is_active=models.BooleanField(default=True)
is_staff=models.BooleanField(default=False)
is_superuser=models.BooleanField(default=False)
USERNAME_FIELD ='username'
REQUIRED_FIELDS=['email','phone','gender']
objects=AccountManager()
def str(self):
return self.username
def has_perm(self,perm,obj=None):
return self.is_admin
def has_module_perms(self, app_lebel):
return True
class StudentAccnt(models.Model):
user=models.OneToOneField(Account, on_delete=models.CASCADE)
reg_number=models.CharField(verbose_name='Reg NO', max_length=10,unique=True)
class StaffAccnt(models.Model):
user=models.OneToOneField(Account, on_delete=models.CASCADE)
is_teaching=models.BooleanField()
Aneesh
Django.db.utils.opertionalerror:Fatal :data base does not exist
Aneesh
Please help
Aneesh
Postgres
Mahshooq
super(Connection, self).init(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to MySQL server on '127.0.0.1' (115)")
Mahshooq
Shihasz
from django.db import models
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager,User
# Create your models here.
GENDER_CHOICES = (
('M', 'Male'),
('F', 'Female')
)
class AccountManager(BaseUserManager):
def create_user(self,email,username,phone,gender,password=None):
if not email:
raise ValueError("email is needed")
if not username:
raise ValueError("uname is needed")
if not phone:
raise ValueError("Phone is needed")
if not gender:
raise ValueError("gender is needed")
user= self.model(
email=self.normalize_email(email),
username=username,
phone=phone,
gender=gender,
)
user.set_password(password)
user.save(using=self._db)
return user
def create_superuser(self,email,username,phone,gender,password):
user=self.create_user(
email=self.normalize_email(email),
password=password,
username=username,
phone=phone,
gender=gender,
)
user.is_admin=True
user.is_staff=True
user.is_superuser=True
user.save(using=self._db)
return user
class Account(AbstractBaseUser):
ACCTYPE = (
('Student', 'Student'),
('Staff', 'Staff')
)
email=models.EmailField(verbose_name='E-mail', max_length=30, unique=True)
username=models.CharField(verbose_name='Username', max_length=30, unique=True)
last_login=models.DateTimeField(verbose_name='Last Login', auto_now=True)
phone=models.CharField(verbose_name='Phone', max_length=50)
gender= models.CharField(choices=GENDER_CHOICES, max_length=128)
acctype = models.CharField(max_length=16, choices=ACCTYPE)
is_admin=models.BooleanField(default=False)
is_active=models.BooleanField(default=True)
is_staff=models.BooleanField(default=False)
is_superuser=models.BooleanField(default=False)
USERNAME_FIELD ='username'
REQUIRED_FIELDS=['email','phone','gender']
objects=AccountManager()
def str(self):
return self.username
def has_perm(self,perm,obj=None):
return self.is_admin
def has_module_perms(self, app_lebel):
return True
class StudentAccnt(models.Model):
user=models.OneToOneField(Account, on_delete=models.CASCADE)
reg_number=models.CharField(verbose_name='Reg NO', max_length=10,unique=True)
class StaffAccnt(models.Model):
user=models.OneToOneField(Account, on_delete=models.CASCADE)
is_teaching=models.BooleanField()
What errors are u getting?
Nitish
I am sending data using postman to my api but it is still showing field is required and i am giving the value to that field please help
Nitish
JoKer
this is the error
Pooja
Hllo everyone
Romila
Hi I'm not getting jira-python library to create issues using rest api token please help me
Pooja
Plzz anyone help me how to I am work on django online tool
Pooja
Plzz guide me
Pooja
How to work with online tool
Anonymous
Aroop
Plz expalin the manager in models
Habibov
good afternoon everyone
Habibov
help how to add this data to the database
S Sidharth
Habibov
in html there are several tables how to add them to a DB at the same time
Pooja
What tool
Like Google colab is a online tool for python practice
Pooja
So I want to know any django online tool for practice
S Sidharth
Василий
I need help) I replaced the admin panel with Grappelli. Everything works fine on a localhost. But after downloading to the Heroku server, the server gives an error: at=error code=H10 desc="App crashed" method=GET path="/" host=new-testing-heroku.herokuapp.com request_id=aa6c2a33-8d39-46e8-95f6-60a3d4580f19 fwd="95.27.151.139" dyno= connect= service= status=503 bytes= protocol=https
Василий
What is the problem? I uploaded the static files.
Василий
2020-03-29T21:21:17.662056+00:00 heroku[web.1]: State changed from crashed to starting
2020-03-29T21:21:25.680993+00:00 heroku[web.1]: State changed from starting to up
2020-03-29T21:21:26.682002+00:00 heroku[web.1]: State changed from up to crashed
Василий
Help me pls) Tell me why my server crashes?
Василий
lokalhost works
Nitish
anyone can tell i am sending data through api and status code is 200 but the data is not saving in model and it is returning blank list
Amit
Dhruva
I am doing reset password using rest-auth but in that user need to manually enter the uid and token after verifying how to prevent from entering manually instead after verifying mail just the new password has to be entered
Pruthvi
Best book to learn django
Pruthvi
After tutorial fr Mdn
Anonymous
minimum_duration = (total_duration / total_file_size) * (MAX_TG_SPLIT_FILE_SIZE)
Anonymous
Cesar
Dhruva
Yash
can anyone please send me some video link where they have differentiated the auth_user and User(custom) table for login
Yash
have been trying with one to one mapping but its not working out
George
George
!djangotut
Doragonsureiyā
Looking for Django tutorials? you can follow these three recommended ones:
* Official documentation and tutorial
* Tutorial from MDN
* Tutorial from django-girls
Yash
https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#changing-to-a-custom-user-model-mid-project
Yash
going through this
Yash
atleast let me know if I am thinking in a right direction
Yash
?
George
Yash
I am not asking for you to do that
Yash
will really appreciate
Yash
if you can drop down some links
Yash
as out there, there are tons of material, and for newbie like me its hard to differentiate which is useful is which is not
Yash
sorry !
Cipher
Please someone help!!!
collectstatic is not working on online server. It is giving type error :
TypeError: expected str, bytes or os.PathLike object, not list.
George
George
Amen
is it okay if i ask about implementing RTC and its issues on safari browsers !
Cipher
Mirco
Anyone, please?
Stop please with this kind of questions
When someone has free time you will get an answer
Akash
How to run huey task in docker.
I am entering this line in my docker file just before gunicorn command.
CMD huey_consumer.py my_app.huey &
CMD my gunicorn command
But the huey consumer does not seem to work.
But if I run huey_consumer.py my_app.huey
Directly from shell it works correctly.
What am I doing wrong
Alex
Doragonsureiyā
Cesar
Cesar
i bet you just exchanged [] with ()
Ashish
Ashish
https://youtu.be/Ml3JTJ_UOz4
blank_
How to use twilio otp authentication in our project
blank_
Please help to make otp verification for login in my django project
Lelouch
Get 127.0.0.1:8000/name.js
Error_abort 404 ( not found )
How to solve
I m getting this error in inspector- console
M
brother how do i get this property?
property
def listcekdocs(self):
return ListCekdoc_set.all()
Sandeep
hey do someone can provide me a django blog app?
Amen
Lelouch
I need social network site django
Lelouch
Or any better project
suggest guys