Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Integr@te System
Hi friend,

check again docs to see what benefit for u:
https://realpython.com/django-migrations-a-primer/#ensuring-model-definitions-and-the-database-schema-in-sync

Auth customizing:
https://docs.djangoproject.com/en/2.2/topics/auth/customizing/


On Wed, Nov 27, 2019, 12:34 Raja Sekar Sambath  wrote:

> Hi,
>
> If you have deleted your old db and creating a fresh database, then delete
> all files generated previously using migration command and do migration
>
> (have a backup before deleting files) ;)
>
> On Tue, 26 Nov 2019 at 23:57, Ahmad Saki 
> wrote:
>
>> Hi friend,
>>
>> When I want to create my custom authentication model User. I have got
>> error such as 'FieldDoesNotExist 'userid''.
>> So, I have deleted all of these previous migration_files, re-create
>> database and makemigrations. But cannot able to migrate again.
>>
>>
>> On Wednesday, November 27, 2019 at 12:05:24 AM UTC+6, Integr@te System
>> wrote:
>>>
>>> Hi friend,
>>>
>>> plz check these files: '  # Generated by Django 2.2.3 on 2019-11-26
>>> 15:36 ' and another (if u have), to see separating.
>>>
>>> On Tue, Nov 26, 2019, 23:44 Ahmad Saki  wrote:
>>>
 Hello Dear,
 Please explain with more words. How do I solve this problem? What can I
 do?

 On Tuesday, November 26, 2019 at 9:54:26 PM UTC+6, Integr@te System
 wrote:
>
> Hi man,
>
> And u see error occur again, isn't it?
> Do you differ two file that app output when you migrated?
>
> On Tue, Nov 26, 2019, 22:40 Ahmad Saki  wrote:
>
>> organization.Organization model:
>>
>> from django.db import models
>>
>> class Organization(models.Model):
>>orgid = models.IntegerField(max_length=6, primary_key=True)
>>name = models.CharField(max_length=50)
>>phone = models.CharField(max_length=20,null=True,blank=True,
>> default=None)
>>email = models.CharField(max_length=50,null=True,blank=True,
>> default=None)
>>mobile = models.CharField(max_length=20,null=True,blank=True,
>> default=None)
>>permanent_address = models.CharField(max_length=200,null=True,
>> blank=True,default=None)
>>present_address = models.CharField(max_length=200,null=True,blank=
>> True,default=None)
>>remark = models.CharField(max_length=500,null=True,blank=True,
>> default=None)
>>
>> And migration:
>>
>> # Generated by Django 2.2.3 on 2019-11-26 15:36
>>
>> from django.db import migrations, models
>>
>>
>> class Migration(migrations.Migration):
>>
>> initial = True
>>
>> dependencies = [
>>]
>>
>> operations = [
>>migrations.CreateModel(
>>name='Organization',
>>fields=[
>>('orgid', models.IntegerField(max_length=6,
>> primary_key=True, serialize=False)),
>>('name', models.CharField(max_length=50)),
>>('phone', models.CharField(blank=True, default=None,
>> max_length=20, null=True)),
>>('email', models.CharField(blank=True, default=None,
>> max_length=50, null=True)),
>>('mobile', models.CharField(blank=True, default=None,
>> max_length=20, null=True)),
>>('permanent_address', models.CharField(blank=True,
>> default=None, max_length=200, null=True)),
>>('present_address', models.CharField(blank=True,
>> default=None, max_length=200, null=True)),
>>('remark', models.CharField(blank=True, default=None,
>> max_length=500, null=True)),
>>],
>>),
>>]
>>
>>
>>
>>
>> On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System
>> wrote:
>>>
>>> hi, inspect your typo and Organization model.
>>>
>>> On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:
>>>
 Dear,
 Thanks for your response.
 I use the foreign key field 'orgid' or not but got the same error.
 If I want to use this then where is my fault for this error!


 On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te
 System wrote:
>
> Hi man,
>
> Check 'class UserManager(): ..orgid = org_obj '
>
>
>
>
> On Tue, Nov 26, 2019, 01:40 Ahmad Saki 
> wrote:
>
>> My custom authentication model in django:
>>
>> from django.db import models
>> from django.contrib.auth.models import (
>> AbstractBaseUser, BaseUserManager
>> )
>> from organization.models import Organization
>>
>>
>> class UserManager(BaseUserManager):
>> # use_in_migrations = True
>>
>> # python manage.py createsuperuser
>> def create_user(self, orgid, username, email,  password=None, 
>> 

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Raja Sekar Sambath
Hi,

If you have deleted your old db and creating a fresh database, then delete
all files generated previously using migration command and do migration

(have a backup before deleting files) ;)

On Tue, 26 Nov 2019 at 23:57, Ahmad Saki  wrote:

> Hi friend,
>
> When I want to create my custom authentication model User. I have got
> error such as 'FieldDoesNotExist 'userid''.
> So, I have deleted all of these previous migration_files, re-create
> database and makemigrations. But cannot able to migrate again.
>
>
> On Wednesday, November 27, 2019 at 12:05:24 AM UTC+6, Integr@te System
> wrote:
>>
>> Hi friend,
>>
>> plz check these files: '  # Generated by Django 2.2.3 on 2019-11-26 15:36 '
>> and another (if u have), to see separating.
>>
>> On Tue, Nov 26, 2019, 23:44 Ahmad Saki  wrote:
>>
>>> Hello Dear,
>>> Please explain with more words. How do I solve this problem? What can I
>>> do?
>>>
>>> On Tuesday, November 26, 2019 at 9:54:26 PM UTC+6, Integr@te System
>>> wrote:

 Hi man,

 And u see error occur again, isn't it?
 Do you differ two file that app output when you migrated?

 On Tue, Nov 26, 2019, 22:40 Ahmad Saki  wrote:

> organization.Organization model:
>
> from django.db import models
>
> class Organization(models.Model):
>orgid = models.IntegerField(max_length=6, primary_key=True)
>name = models.CharField(max_length=50)
>phone = models.CharField(max_length=20,null=True,blank=True,default
> =None)
>email = models.CharField(max_length=50,null=True,blank=True,default
> =None)
>mobile = models.CharField(max_length=20,null=True,blank=True,
> default=None)
>permanent_address = models.CharField(max_length=200,null=True,blank
> =True,default=None)
>present_address = models.CharField(max_length=200,null=True,blank=
> True,default=None)
>remark = models.CharField(max_length=500,null=True,blank=True,
> default=None)
>
> And migration:
>
> # Generated by Django 2.2.3 on 2019-11-26 15:36
>
> from django.db import migrations, models
>
>
> class Migration(migrations.Migration):
>
> initial = True
>
> dependencies = [
>]
>
> operations = [
>migrations.CreateModel(
>name='Organization',
>fields=[
>('orgid', models.IntegerField(max_length=6, primary_key
> =True, serialize=False)),
>('name', models.CharField(max_length=50)),
>('phone', models.CharField(blank=True, default=None,
> max_length=20, null=True)),
>('email', models.CharField(blank=True, default=None,
> max_length=50, null=True)),
>('mobile', models.CharField(blank=True, default=None,
> max_length=20, null=True)),
>('permanent_address', models.CharField(blank=True,
> default=None, max_length=200, null=True)),
>('present_address', models.CharField(blank=True,
> default=None, max_length=200, null=True)),
>('remark', models.CharField(blank=True, default=None,
> max_length=500, null=True)),
>],
>),
>]
>
>
>
>
> On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System
> wrote:
>>
>> hi, inspect your typo and Organization model.
>>
>> On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:
>>
>>> Dear,
>>> Thanks for your response.
>>> I use the foreign key field 'orgid' or not but got the same error.
>>> If I want to use this then where is my fault for this error!
>>>
>>>
>>> On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te
>>> System wrote:

 Hi man,

 Check 'class UserManager(): ..orgid = org_obj '




 On Tue, Nov 26, 2019, 01:40 Ahmad Saki 
 wrote:

> My custom authentication model in django:
>
> from django.db import models
> from django.contrib.auth.models import (
> AbstractBaseUser, BaseUserManager
> )
> from organization.models import Organization
>
>
> class UserManager(BaseUserManager):
> # use_in_migrations = True
>
> # python manage.py createsuperuser
> def create_user(self, orgid, username, email,  password=None, 
> is_admin=False, is_staff=False, is_active=True):
> if not orgid:
> raise ValueError("Organization of user must not empty")
> elif not username:
> raise ValueError("User must have an username")
> elif not email:
> raise ValueError("User must have an email address")
>
> org_obj = Organization.objects.all(orgid=orgid)
> user_obj = self.model(

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Ahmad Saki
Hi friend,

When I want to create my custom authentication model User. I have got error 
such as 'FieldDoesNotExist 'userid''.
So, I have deleted all of these previous migration_files, re-create 
database and makemigrations. But cannot able to migrate again.


On Wednesday, November 27, 2019 at 12:05:24 AM UTC+6, Integr@te System 
wrote:
>
> Hi friend,
>
> plz check these files: '  # Generated by Django 2.2.3 on 2019-11-26 15:36 ' 
> and another (if u have), to see separating.
>
> On Tue, Nov 26, 2019, 23:44 Ahmad Saki > 
> wrote:
>
>> Hello Dear,
>> Please explain with more words. How do I solve this problem? What can I 
>> do?
>>
>> On Tuesday, November 26, 2019 at 9:54:26 PM UTC+6, Integr@te System wrote:
>>>
>>> Hi man,
>>>
>>> And u see error occur again, isn't it?
>>> Do you differ two file that app output when you migrated?
>>>
>>> On Tue, Nov 26, 2019, 22:40 Ahmad Saki  wrote:
>>>
 organization.Organization model:

 from django.db import models

 class Organization(models.Model):
orgid = models.IntegerField(max_length=6, primary_key=True)
name = models.CharField(max_length=50)
phone = models.CharField(max_length=20,null=True,blank=True,default=
 None)
email = models.CharField(max_length=50,null=True,blank=True,default=
 None)
mobile = models.CharField(max_length=20,null=True,blank=True,default
 =None)
permanent_address = models.CharField(max_length=200,null=True,blank=
 True,default=None)
present_address = models.CharField(max_length=200,null=True,blank=
 True,default=None)
remark = models.CharField(max_length=500,null=True,blank=True,
 default=None)

 And migration:

 # Generated by Django 2.2.3 on 2019-11-26 15:36

 from django.db import migrations, models


 class Migration(migrations.Migration):

 initial = True

 dependencies = [
]

 operations = [
migrations.CreateModel(
name='Organization',
fields=[
('orgid', models.IntegerField(max_length=6, primary_key=
 True, serialize=False)),
('name', models.CharField(max_length=50)),
('phone', models.CharField(blank=True, default=None, 
 max_length=20, null=True)),
('email', models.CharField(blank=True, default=None, 
 max_length=50, null=True)),
('mobile', models.CharField(blank=True, default=None, 
 max_length=20, null=True)),
('permanent_address', models.CharField(blank=True, 
 default=None, max_length=200, null=True)),
('present_address', models.CharField(blank=True, default
 =None, max_length=200, null=True)),
('remark', models.CharField(blank=True, default=None, 
 max_length=500, null=True)),
],
),
]




 On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System 
 wrote:
>
> hi, inspect your typo and Organization model.
>
> On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:
>
>> Dear,
>> Thanks for your response.
>> I use the foreign key field 'orgid' or not but got the same error. If 
>> I want to use this then where is my fault for this error!
>>
>>
>> On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System 
>> wrote:
>>>
>>> Hi man,
>>>
>>> Check 'class UserManager(): ..orgid = org_obj '
>>>
>>>
>>>
>>>
>>> On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:
>>>
 My custom authentication model in django:

 from django.db import models
 from django.contrib.auth.models import (
 AbstractBaseUser, BaseUserManager
 )
 from organization.models import Organization


 class UserManager(BaseUserManager):
 # use_in_migrations = True

 # python manage.py createsuperuser
 def create_user(self, orgid, username, email,  password=None, 
 is_admin=False, is_staff=False, is_active=True):
 if not orgid:
 raise ValueError("Organization of user must not empty")
 elif not username:
 raise ValueError("User must have an username")
 elif not email:
 raise ValueError("User must have an email address")

 org_obj = Organization.objects.all(orgid=orgid)
 user_obj = self.model(
 orgid=org_obj,
 username=username,
 email = self.normalize_email(email),
 password=password
 )
 user_obj.set_password(password)
 user_obj.admin=is_admin
 user_obj.staff=is_staff
 user_obj.active=is_active
 user_obj.save(using=self._db)
 

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Integr@te System
Hi friend,

plz check these files: '  # Generated by Django 2.2.3 on 2019-11-26 15:36 '
and another (if u have), to see separating.

On Tue, Nov 26, 2019, 23:44 Ahmad Saki  wrote:

> Hello Dear,
> Please explain with more words. How do I solve this problem? What can I do?
>
> On Tuesday, November 26, 2019 at 9:54:26 PM UTC+6, Integr@te System wrote:
>>
>> Hi man,
>>
>> And u see error occur again, isn't it?
>> Do you differ two file that app output when you migrated?
>>
>> On Tue, Nov 26, 2019, 22:40 Ahmad Saki  wrote:
>>
>>> organization.Organization model:
>>>
>>> from django.db import models
>>>
>>> class Organization(models.Model):
>>>orgid = models.IntegerField(max_length=6, primary_key=True)
>>>name = models.CharField(max_length=50)
>>>phone = models.CharField(max_length=20,null=True,blank=True,default=
>>> None)
>>>email = models.CharField(max_length=50,null=True,blank=True,default=
>>> None)
>>>mobile = models.CharField(max_length=20,null=True,blank=True,default=
>>> None)
>>>permanent_address = models.CharField(max_length=200,null=True,blank=
>>> True,default=None)
>>>present_address = models.CharField(max_length=200,null=True,blank=
>>> True,default=None)
>>>remark = models.CharField(max_length=500,null=True,blank=True,default
>>> =None)
>>>
>>> And migration:
>>>
>>> # Generated by Django 2.2.3 on 2019-11-26 15:36
>>>
>>> from django.db import migrations, models
>>>
>>>
>>> class Migration(migrations.Migration):
>>>
>>> initial = True
>>>
>>> dependencies = [
>>>]
>>>
>>> operations = [
>>>migrations.CreateModel(
>>>name='Organization',
>>>fields=[
>>>('orgid', models.IntegerField(max_length=6, primary_key=
>>> True, serialize=False)),
>>>('name', models.CharField(max_length=50)),
>>>('phone', models.CharField(blank=True, default=None,
>>> max_length=20, null=True)),
>>>('email', models.CharField(blank=True, default=None,
>>> max_length=50, null=True)),
>>>('mobile', models.CharField(blank=True, default=None,
>>> max_length=20, null=True)),
>>>('permanent_address', models.CharField(blank=True,
>>> default=None, max_length=200, null=True)),
>>>('present_address', models.CharField(blank=True, default=
>>> None, max_length=200, null=True)),
>>>('remark', models.CharField(blank=True, default=None,
>>> max_length=500, null=True)),
>>>],
>>>),
>>>]
>>>
>>>
>>>
>>>
>>> On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System
>>> wrote:

 hi, inspect your typo and Organization model.

 On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:

> Dear,
> Thanks for your response.
> I use the foreign key field 'orgid' or not but got the same error. If
> I want to use this then where is my fault for this error!
>
>
> On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System
> wrote:
>>
>> Hi man,
>>
>> Check 'class UserManager(): ..orgid = org_obj '
>>
>>
>>
>>
>> On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:
>>
>>> My custom authentication model in django:
>>>
>>> from django.db import models
>>> from django.contrib.auth.models import (
>>> AbstractBaseUser, BaseUserManager
>>> )
>>> from organization.models import Organization
>>>
>>>
>>> class UserManager(BaseUserManager):
>>> # use_in_migrations = True
>>>
>>> # python manage.py createsuperuser
>>> def create_user(self, orgid, username, email,  password=None, 
>>> is_admin=False, is_staff=False, is_active=True):
>>> if not orgid:
>>> raise ValueError("Organization of user must not empty")
>>> elif not username:
>>> raise ValueError("User must have an username")
>>> elif not email:
>>> raise ValueError("User must have an email address")
>>>
>>> org_obj = Organization.objects.all(orgid=orgid)
>>> user_obj = self.model(
>>> orgid=org_obj,
>>> username=username,
>>> email = self.normalize_email(email),
>>> password=password
>>> )
>>> user_obj.set_password(password)
>>> user_obj.admin=is_admin
>>> user_obj.staff=is_staff
>>> user_obj.active=is_active
>>> user_obj.save(using=self._db)
>>> return user_obj
>>>
>>> # python manage.py createsuperuser
>>> def create_superuser(self, orgid, username, email, password=None):
>>> user = 
>>> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
>>> return user
>>>
>>> def create_staffuser(self, orgid, username, email, password=None):
>>> user = 
>>> 

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Ahmad Saki
Hello Dear,
Please explain with more words. How do I solve this problem? What can I do?

On Tuesday, November 26, 2019 at 9:54:26 PM UTC+6, Integr@te System wrote:
>
> Hi man,
>
> And u see error occur again, isn't it?
> Do you differ two file that app output when you migrated?
>
> On Tue, Nov 26, 2019, 22:40 Ahmad Saki > 
> wrote:
>
>> organization.Organization model:
>>
>> from django.db import models
>>
>> class Organization(models.Model):
>>orgid = models.IntegerField(max_length=6, primary_key=True)
>>name = models.CharField(max_length=50)
>>phone = models.CharField(max_length=20,null=True,blank=True,default=
>> None)
>>email = models.CharField(max_length=50,null=True,blank=True,default=
>> None)
>>mobile = models.CharField(max_length=20,null=True,blank=True,default=
>> None)
>>permanent_address = models.CharField(max_length=200,null=True,blank=
>> True,default=None)
>>present_address = models.CharField(max_length=200,null=True,blank=True
>> ,default=None)
>>remark = models.CharField(max_length=500,null=True,blank=True,default=
>> None)
>>
>> And migration:
>>
>> # Generated by Django 2.2.3 on 2019-11-26 15:36
>>
>> from django.db import migrations, models
>>
>>
>> class Migration(migrations.Migration):
>>
>> initial = True
>>
>> dependencies = [
>>]
>>
>> operations = [
>>migrations.CreateModel(
>>name='Organization',
>>fields=[
>>('orgid', models.IntegerField(max_length=6, primary_key=
>> True, serialize=False)),
>>('name', models.CharField(max_length=50)),
>>('phone', models.CharField(blank=True, default=None, 
>> max_length=20, null=True)),
>>('email', models.CharField(blank=True, default=None, 
>> max_length=50, null=True)),
>>('mobile', models.CharField(blank=True, default=None, 
>> max_length=20, null=True)),
>>('permanent_address', models.CharField(blank=True, default
>> =None, max_length=200, null=True)),
>>('present_address', models.CharField(blank=True, default=
>> None, max_length=200, null=True)),
>>('remark', models.CharField(blank=True, default=None, 
>> max_length=500, null=True)),
>>],
>>),
>>]
>>
>>
>>
>>
>> On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System wrote:
>>>
>>> hi, inspect your typo and Organization model.
>>>
>>> On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:
>>>
 Dear,
 Thanks for your response.
 I use the foreign key field 'orgid' or not but got the same error. If I 
 want to use this then where is my fault for this error!


 On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System 
 wrote:
>
> Hi man,
>
> Check 'class UserManager(): ..orgid = org_obj '
>
>
>
>
> On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:
>
>> My custom authentication model in django:
>>
>> from django.db import models
>> from django.contrib.auth.models import (
>> AbstractBaseUser, BaseUserManager
>> )
>> from organization.models import Organization
>>
>>
>> class UserManager(BaseUserManager):
>> # use_in_migrations = True
>>
>> # python manage.py createsuperuser
>> def create_user(self, orgid, username, email,  password=None, 
>> is_admin=False, is_staff=False, is_active=True):
>> if not orgid:
>> raise ValueError("Organization of user must not empty")
>> elif not username:
>> raise ValueError("User must have an username")
>> elif not email:
>> raise ValueError("User must have an email address")
>>
>> org_obj = Organization.objects.all(orgid=orgid)
>> user_obj = self.model(
>> orgid=org_obj,
>> username=username,
>> email = self.normalize_email(email),
>> password=password
>> )
>> user_obj.set_password(password)
>> user_obj.admin=is_admin
>> user_obj.staff=is_staff
>> user_obj.active=is_active
>> user_obj.save(using=self._db)
>> return user_obj
>>
>> # python manage.py createsuperuser
>> def create_superuser(self, orgid, username, email, password=None):
>> user = 
>> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
>> return user
>>
>> def create_staffuser(self, orgid, username, email, password=None):
>> user = 
>> self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
>> return user
>>
>> class User(AbstractBaseUser):
>> orgid   = models.ForeignKey(Organization, max_length=6, 
>> on_delete=models.CASCADE)
>> username= models.CharField(primary_key=True, max_length=50) 
>> email   = models.EmailField(max_length=255, unique=True, 

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Integr@te System
Hi man,

And u see error occur again, isn't it?
Do you differ two file that app output when you migrated?

On Tue, Nov 26, 2019, 22:40 Ahmad Saki  wrote:

> organization.Organization model:
>
> from django.db import models
>
> class Organization(models.Model):
>orgid = models.IntegerField(max_length=6, primary_key=True)
>name = models.CharField(max_length=50)
>phone = models.CharField(max_length=20,null=True,blank=True,default=
> None)
>email = models.CharField(max_length=50,null=True,blank=True,default=
> None)
>mobile = models.CharField(max_length=20,null=True,blank=True,default=
> None)
>permanent_address = models.CharField(max_length=200,null=True,blank=
> True,default=None)
>present_address = models.CharField(max_length=200,null=True,blank=True,
> default=None)
>remark = models.CharField(max_length=500,null=True,blank=True,default=
> None)
>
> And migration:
>
> # Generated by Django 2.2.3 on 2019-11-26 15:36
>
> from django.db import migrations, models
>
>
> class Migration(migrations.Migration):
>
> initial = True
>
> dependencies = [
>]
>
> operations = [
>migrations.CreateModel(
>name='Organization',
>fields=[
>('orgid', models.IntegerField(max_length=6, primary_key=
> True, serialize=False)),
>('name', models.CharField(max_length=50)),
>('phone', models.CharField(blank=True, default=None,
> max_length=20, null=True)),
>('email', models.CharField(blank=True, default=None,
> max_length=50, null=True)),
>('mobile', models.CharField(blank=True, default=None,
> max_length=20, null=True)),
>('permanent_address', models.CharField(blank=True, default=
> None, max_length=200, null=True)),
>('present_address', models.CharField(blank=True, default=
> None, max_length=200, null=True)),
>('remark', models.CharField(blank=True, default=None,
> max_length=500, null=True)),
>],
>),
>]
>
>
>
>
> On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System wrote:
>>
>> hi, inspect your typo and Organization model.
>>
>> On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:
>>
>>> Dear,
>>> Thanks for your response.
>>> I use the foreign key field 'orgid' or not but got the same error. If I
>>> want to use this then where is my fault for this error!
>>>
>>>
>>> On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System
>>> wrote:

 Hi man,

 Check 'class UserManager(): ..orgid = org_obj '




 On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:

> My custom authentication model in django:
>
> from django.db import models
> from django.contrib.auth.models import (
> AbstractBaseUser, BaseUserManager
> )
> from organization.models import Organization
>
>
> class UserManager(BaseUserManager):
> # use_in_migrations = True
>
> # python manage.py createsuperuser
> def create_user(self, orgid, username, email,  password=None, 
> is_admin=False, is_staff=False, is_active=True):
> if not orgid:
> raise ValueError("Organization of user must not empty")
> elif not username:
> raise ValueError("User must have an username")
> elif not email:
> raise ValueError("User must have an email address")
>
> org_obj = Organization.objects.all(orgid=orgid)
> user_obj = self.model(
> orgid=org_obj,
> username=username,
> email = self.normalize_email(email),
> password=password
> )
> user_obj.set_password(password)
> user_obj.admin=is_admin
> user_obj.staff=is_staff
> user_obj.active=is_active
> user_obj.save(using=self._db)
> return user_obj
>
> # python manage.py createsuperuser
> def create_superuser(self, orgid, username, email, password=None):
> user = 
> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
> return user
>
> def create_staffuser(self, orgid, username, email, password=None):
> user = 
> self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
> return user
>
> class User(AbstractBaseUser):
> orgid   = models.ForeignKey(Organization, max_length=6, 
> on_delete=models.CASCADE)
> username= models.CharField(primary_key=True, max_length=50)
> email   = models.EmailField(max_length=255, unique=True, null=False, 
> blank=False)
> admin   = models.BooleanField(default=False)
> staff   = models.BooleanField(default=False)
> active  = models.BooleanField(default=True)
> date_joined = models.DateTimeField(auto_now_add=True)
>
> objects = UserManager()
>
> USERNAME_FIELD = 

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Ahmad Saki
organization.Organization model:

from django.db import models

class Organization(models.Model):
   orgid = models.IntegerField(max_length=6, primary_key=True)
   name = models.CharField(max_length=50)
   phone = models.CharField(max_length=20,null=True,blank=True,default=None)
   email = models.CharField(max_length=50,null=True,blank=True,default=None)
   mobile = models.CharField(max_length=20,null=True,blank=True,default=None
)
   permanent_address = models.CharField(max_length=200,null=True,blank=True,
default=None)
   present_address = models.CharField(max_length=200,null=True,blank=True,
default=None)
   remark = models.CharField(max_length=500,null=True,blank=True,default=
None)

And migration:

# Generated by Django 2.2.3 on 2019-11-26 15:36

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = [
   ]

operations = [
   migrations.CreateModel(
   name='Organization',
   fields=[
   ('orgid', models.IntegerField(max_length=6, primary_key=True, 
serialize=False)),
   ('name', models.CharField(max_length=50)),
   ('phone', models.CharField(blank=True, default=None, 
max_length=20, null=True)),
   ('email', models.CharField(blank=True, default=None, 
max_length=50, null=True)),
   ('mobile', models.CharField(blank=True, default=None, 
max_length=20, null=True)),
   ('permanent_address', models.CharField(blank=True, default=
None, max_length=200, null=True)),
   ('present_address', models.CharField(blank=True, default=None
, max_length=200, null=True)),
   ('remark', models.CharField(blank=True, default=None, 
max_length=500, null=True)),
   ],
   ),
   ]




On Tuesday, November 26, 2019 at 8:26:13 PM UTC+6, Integr@te System wrote:
>
> hi, inspect your typo and Organization model.
>
> On Tue, Nov 26, 2019, 16:31 Ahmad Saki > 
> wrote:
>
>> Dear,
>> Thanks for your response.
>> I use the foreign key field 'orgid' or not but got the same error. If I 
>> want to use this then where is my fault for this error!
>>
>>
>> On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System 
>> wrote:
>>>
>>> Hi man,
>>>
>>> Check 'class UserManager(): ..orgid = org_obj '
>>>
>>>
>>>
>>>
>>> On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:
>>>
 My custom authentication model in django:

 from django.db import models
 from django.contrib.auth.models import (
 AbstractBaseUser, BaseUserManager
 )
 from organization.models import Organization


 class UserManager(BaseUserManager):
 # use_in_migrations = True

 # python manage.py createsuperuser
 def create_user(self, orgid, username, email,  password=None, 
 is_admin=False, is_staff=False, is_active=True):
 if not orgid:
 raise ValueError("Organization of user must not empty")
 elif not username:
 raise ValueError("User must have an username")
 elif not email:
 raise ValueError("User must have an email address")

 org_obj = Organization.objects.all(orgid=orgid)
 user_obj = self.model(
 orgid=org_obj,
 username=username,
 email = self.normalize_email(email),
 password=password
 )
 user_obj.set_password(password)
 user_obj.admin=is_admin
 user_obj.staff=is_staff
 user_obj.active=is_active
 user_obj.save(using=self._db)
 return user_obj

 # python manage.py createsuperuser
 def create_superuser(self, orgid, username, email, password=None):
 user = 
 self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
 return user

 def create_staffuser(self, orgid, username, email, password=None):
 user = 
 self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
 return user

 class User(AbstractBaseUser):
 orgid   = models.ForeignKey(Organization, max_length=6, 
 on_delete=models.CASCADE)
 username= models.CharField(primary_key=True, max_length=50) 
 email   = models.EmailField(max_length=255, unique=True, null=False, 
 blank=False)
 admin   = models.BooleanField(default=False)
 staff   = models.BooleanField(default=False)
 active  = models.BooleanField(default=True)
 date_joined = models.DateTimeField(auto_now_add=True)

 objects = UserManager()

 USERNAME_FIELD = "username"
 # REQUIRED_FIELDS must contain all required fields on your User model, 
 # but should not contain the USERNAME_FIELD or password as these fields 
 will always be prompted for.
 REQUIRED_FIELDS = ['orgid','email']

 class Meta:
 app_label = "user"
 db_table = "user"

 def __str__(self):

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Integr@te System
hi, inspect your typo and Organization model.

On Tue, Nov 26, 2019, 16:31 Ahmad Saki  wrote:

> Dear,
> Thanks for your response.
> I use the foreign key field 'orgid' or not but got the same error. If I
> want to use this then where is my fault for this error!
>
>
> On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System
> wrote:
>>
>> Hi man,
>>
>> Check 'class UserManager(): ..orgid = org_obj '
>>
>>
>>
>>
>> On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:
>>
>>> My custom authentication model in django:
>>>
>>> from django.db import models
>>> from django.contrib.auth.models import (
>>> AbstractBaseUser, BaseUserManager
>>> )
>>> from organization.models import Organization
>>>
>>>
>>> class UserManager(BaseUserManager):
>>> # use_in_migrations = True
>>>
>>> # python manage.py createsuperuser
>>> def create_user(self, orgid, username, email,  password=None, 
>>> is_admin=False, is_staff=False, is_active=True):
>>> if not orgid:
>>> raise ValueError("Organization of user must not empty")
>>> elif not username:
>>> raise ValueError("User must have an username")
>>> elif not email:
>>> raise ValueError("User must have an email address")
>>>
>>> org_obj = Organization.objects.all(orgid=orgid)
>>> user_obj = self.model(
>>> orgid=org_obj,
>>> username=username,
>>> email = self.normalize_email(email),
>>> password=password
>>> )
>>> user_obj.set_password(password)
>>> user_obj.admin=is_admin
>>> user_obj.staff=is_staff
>>> user_obj.active=is_active
>>> user_obj.save(using=self._db)
>>> return user_obj
>>>
>>> # python manage.py createsuperuser
>>> def create_superuser(self, orgid, username, email, password=None):
>>> user = 
>>> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
>>> return user
>>>
>>> def create_staffuser(self, orgid, username, email, password=None):
>>> user = 
>>> self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
>>> return user
>>>
>>> class User(AbstractBaseUser):
>>> orgid   = models.ForeignKey(Organization, max_length=6, 
>>> on_delete=models.CASCADE)
>>> username= models.CharField(primary_key=True, max_length=50)
>>> email   = models.EmailField(max_length=255, unique=True, null=False, 
>>> blank=False)
>>> admin   = models.BooleanField(default=False)
>>> staff   = models.BooleanField(default=False)
>>> active  = models.BooleanField(default=True)
>>> date_joined = models.DateTimeField(auto_now_add=True)
>>>
>>> objects = UserManager()
>>>
>>> USERNAME_FIELD = "username"
>>> # REQUIRED_FIELDS must contain all required fields on your User model,
>>> # but should not contain the USERNAME_FIELD or password as these fields 
>>> will always be prompted for.
>>> REQUIRED_FIELDS = ['orgid','email']
>>>
>>> class Meta:
>>> app_label = "user"
>>> db_table = "user"
>>>
>>> def __str__(self):
>>> return self.username
>>>
>>> def get_full_name(self):
>>> return self.username
>>>
>>> def get_short_name(self):
>>> return self.username
>>>
>>> # this methods are require to login super user from admin panel
>>> def has_perm(self, perm, obj=None):
>>> return self.is_staff
>>>
>>> # this methods are require to login super user from admin panel
>>> def has_module_perms(self, app_label):
>>> return self.is_staff
>>>
>>> @property
>>> def is_admin(self):
>>> return self.admin
>>>
>>> @property
>>> def is_staff(self):
>>> return self.staff
>>>
>>> @property
>>> def is_active(self):
>>> return self.active
>>>
>>>
>>>
>>> When I create migrations it creates:
>>>
>>> from django.db import migrations, models
>>> import django.db.models.deletion
>>> import user.models
>>>
>>>
>>> class Migration(migrations.Migration):
>>>
>>> initial = True
>>>
>>> dependencies = [
>>> ('organization', '0001_initial'),
>>> ]
>>>
>>> operations = [
>>> migrations.CreateModel(
>>> name='User',
>>> fields=[
>>> ('password', models.CharField(max_length=128, 
>>> verbose_name='password')),
>>> ('last_login', models.DateTimeField(blank=True, null=True, 
>>> verbose_name='last login')),
>>> ('username', models.CharField(max_length=50, primary_key=True, 
>>> serialize=False)),
>>> ('email', models.EmailField(max_length=255, unique=True)),
>>> ('admin', models.BooleanField(default=False)),
>>> ('staff', models.BooleanField(default=False)),
>>> ('active', models.BooleanField(default=True)),
>>> ('date_joined', models.DateTimeField(auto_now_add=True)),
>>> ('orgid', models.ForeignKey(max_length=6, 
>>> on_delete=django.db.models.deletion.CASCADE, 
>>> to='organization.Organization')),
>>> ],
>>> options={
>>> 'db_table': 'user',
>>> },
>>> managers=[
>>>   

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-26 Thread Ahmad Saki
Dear,
Thanks for your response.
I use the foreign key field 'orgid' or not but got the same error. If I 
want to use this then where is my fault for this error!


On Tuesday, November 26, 2019 at 12:11:58 PM UTC+6, Integr@te System wrote:
>
> Hi man,
>
> Check 'class UserManager(): ..orgid = org_obj '
>
>
>
>
> On Tue, Nov 26, 2019, 01:40 Ahmad Saki > 
> wrote:
>
>> My custom authentication model in django:
>>
>> from django.db import models
>> from django.contrib.auth.models import (
>> AbstractBaseUser, BaseUserManager
>> )
>> from organization.models import Organization
>>
>>
>> class UserManager(BaseUserManager):
>> # use_in_migrations = True
>>
>> # python manage.py createsuperuser
>> def create_user(self, orgid, username, email,  password=None, 
>> is_admin=False, is_staff=False, is_active=True):
>> if not orgid:
>> raise ValueError("Organization of user must not empty")
>> elif not username:
>> raise ValueError("User must have an username")
>> elif not email:
>> raise ValueError("User must have an email address")
>>
>> org_obj = Organization.objects.all(orgid=orgid)
>> user_obj = self.model(
>> orgid=org_obj,
>> username=username,
>> email = self.normalize_email(email),
>> password=password
>> )
>> user_obj.set_password(password)
>> user_obj.admin=is_admin
>> user_obj.staff=is_staff
>> user_obj.active=is_active
>> user_obj.save(using=self._db)
>> return user_obj
>>
>> # python manage.py createsuperuser
>> def create_superuser(self, orgid, username, email, password=None):
>> user = 
>> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
>> return user
>>
>> def create_staffuser(self, orgid, username, email, password=None):
>> user = 
>> self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
>> return user
>>
>> class User(AbstractBaseUser):
>> orgid   = models.ForeignKey(Organization, max_length=6, 
>> on_delete=models.CASCADE)
>> username= models.CharField(primary_key=True, max_length=50) 
>> email   = models.EmailField(max_length=255, unique=True, null=False, 
>> blank=False)
>> admin   = models.BooleanField(default=False)
>> staff   = models.BooleanField(default=False)
>> active  = models.BooleanField(default=True)
>> date_joined = models.DateTimeField(auto_now_add=True)
>>
>> objects = UserManager()
>>
>> USERNAME_FIELD = "username"
>> # REQUIRED_FIELDS must contain all required fields on your User model, 
>> # but should not contain the USERNAME_FIELD or password as these fields will 
>> always be prompted for.
>> REQUIRED_FIELDS = ['orgid','email']
>>
>> class Meta:
>> app_label = "user"
>> db_table = "user"
>>
>> def __str__(self):
>> return self.username
>>
>> def get_full_name(self):
>> return self.username
>>
>> def get_short_name(self):
>> return self.username
>>
>> # this methods are require to login super user from admin panel
>> def has_perm(self, perm, obj=None):
>> return self.is_staff
>>
>> # this methods are require to login super user from admin panel
>> def has_module_perms(self, app_label):
>> return self.is_staff
>>
>> @property
>> def is_admin(self):
>> return self.admin
>>
>> @property
>> def is_staff(self):
>> return self.staff
>>
>> @property
>> def is_active(self):
>> return self.active
>>
>>
>>
>> When I create migrations it creates:
>>
>> from django.db import migrations, models
>> import django.db.models.deletion
>> import user.models
>>
>>
>> class Migration(migrations.Migration):
>>
>> initial = True
>>
>> dependencies = [
>> ('organization', '0001_initial'),
>> ]
>>
>> operations = [
>> migrations.CreateModel(
>> name='User',
>> fields=[
>> ('password', models.CharField(max_length=128, 
>> verbose_name='password')),
>> ('last_login', models.DateTimeField(blank=True, null=True, 
>> verbose_name='last login')),
>> ('username', models.CharField(max_length=50, primary_key=True, 
>> serialize=False)),
>> ('email', models.EmailField(max_length=255, unique=True)),
>> ('admin', models.BooleanField(default=False)),
>> ('staff', models.BooleanField(default=False)),
>> ('active', models.BooleanField(default=True)),
>> ('date_joined', models.DateTimeField(auto_now_add=True)),
>> ('orgid', models.ForeignKey(max_length=6, 
>> on_delete=django.db.models.deletion.CASCADE, 
>> to='organization.Organization')),
>> ],
>> options={
>> 'db_table': 'user',
>> },
>> managers=[
>> ('objects', user.models.UserManager()),
>> ],
>> ),
>> ]
>>
>>
>>
>> But when I want to migrate it gives me an error below. Please help me 
>> anyone..
>>
>> Operations to perform:
>>   Apply all migrations: admin, auth, contenttypes, 

Re: self.foreign_related_fields[0] IndexError: tuple index out of range

2019-11-25 Thread Integr@te System
Hi man,

Check 'class UserManager(): ..orgid = org_obj '




On Tue, Nov 26, 2019, 01:40 Ahmad Saki  wrote:

> My custom authentication model in django:
>
> from django.db import models
> from django.contrib.auth.models import (
> AbstractBaseUser, BaseUserManager
> )
> from organization.models import Organization
>
>
> class UserManager(BaseUserManager):
> # use_in_migrations = True
>
> # python manage.py createsuperuser
> def create_user(self, orgid, username, email,  password=None, is_admin=False, 
> is_staff=False, is_active=True):
> if not orgid:
> raise ValueError("Organization of user must not empty")
> elif not username:
> raise ValueError("User must have an username")
> elif not email:
> raise ValueError("User must have an email address")
>
> org_obj = Organization.objects.all(orgid=orgid)
> user_obj = self.model(
> orgid=org_obj,
> username=username,
> email = self.normalize_email(email),
> password=password
> )
> user_obj.set_password(password)
> user_obj.admin=is_admin
> user_obj.staff=is_staff
> user_obj.active=is_active
> user_obj.save(using=self._db)
> return user_obj
>
> # python manage.py createsuperuser
> def create_superuser(self, orgid, username, email, password=None):
> user = 
> self.create_user(orgid,username,email,password=password,is_admin=True,is_staff=True,is_active=True)
> return user
>
> def create_staffuser(self, orgid, username, email, password=None):
> user = 
> self.create_user(orgid,username,email,password=password,is_admin=False,is_staff=True,is_active=True)
> return user
>
> class User(AbstractBaseUser):
> orgid   = models.ForeignKey(Organization, max_length=6, 
> on_delete=models.CASCADE)
> username= models.CharField(primary_key=True, max_length=50)
> email   = models.EmailField(max_length=255, unique=True, null=False, 
> blank=False)
> admin   = models.BooleanField(default=False)
> staff   = models.BooleanField(default=False)
> active  = models.BooleanField(default=True)
> date_joined = models.DateTimeField(auto_now_add=True)
>
> objects = UserManager()
>
> USERNAME_FIELD = "username"
> # REQUIRED_FIELDS must contain all required fields on your User model,
> # but should not contain the USERNAME_FIELD or password as these fields will 
> always be prompted for.
> REQUIRED_FIELDS = ['orgid','email']
>
> class Meta:
> app_label = "user"
> db_table = "user"
>
> def __str__(self):
> return self.username
>
> def get_full_name(self):
> return self.username
>
> def get_short_name(self):
> return self.username
>
> # this methods are require to login super user from admin panel
> def has_perm(self, perm, obj=None):
> return self.is_staff
>
> # this methods are require to login super user from admin panel
> def has_module_perms(self, app_label):
> return self.is_staff
>
> @property
> def is_admin(self):
> return self.admin
>
> @property
> def is_staff(self):
> return self.staff
>
> @property
> def is_active(self):
> return self.active
>
>
>
> When I create migrations it creates:
>
> from django.db import migrations, models
> import django.db.models.deletion
> import user.models
>
>
> class Migration(migrations.Migration):
>
> initial = True
>
> dependencies = [
> ('organization', '0001_initial'),
> ]
>
> operations = [
> migrations.CreateModel(
> name='User',
> fields=[
> ('password', models.CharField(max_length=128, 
> verbose_name='password')),
> ('last_login', models.DateTimeField(blank=True, null=True, 
> verbose_name='last login')),
> ('username', models.CharField(max_length=50, primary_key=True, 
> serialize=False)),
> ('email', models.EmailField(max_length=255, unique=True)),
> ('admin', models.BooleanField(default=False)),
> ('staff', models.BooleanField(default=False)),
> ('active', models.BooleanField(default=True)),
> ('date_joined', models.DateTimeField(auto_now_add=True)),
> ('orgid', models.ForeignKey(max_length=6, 
> on_delete=django.db.models.deletion.CASCADE, to='organization.Organization')),
> ],
> options={
> 'db_table': 'user',
> },
> managers=[
> ('objects', user.models.UserManager()),
> ],
> ),
> ]
>
>
>
> But when I want to migrate it gives me an error below. Please help me
> anyone..
>
> Operations to perform:
>   Apply all migrations: admin, auth, contenttypes, organization, sessions, 
> user
> Running migrations:
>   Applying admin.0004_auto_20191118_2315...Traceback (most recent call last):
>   File "manage.py", line 21, in 
> main()
>   File "manage.py", line 17, in main
> execute_from_command_line(sys.argv)
>   File 
> "C:\Users\ZAB-SAKI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\django\core\management\__init__.py",
>  line 381, in