Defined Custom User Model for Cassandra based authentication:
class CustomUser(DjangoCassandraModel):
userid = cassandra_columns.UUID(primary_key=True , default=uuid.uuid4,db_field='userid')
username = cassandra_columns.Text(required=True)
password = cassandra_columns.Text(required=True)
email = cassandra_columns.Text(primary_key=True,required=True)
first_name = cassandra_columns.Text(max_length=30,required=False)
last_name = cassandra_columns.Text(max_length=30,required=False)
is_staff = cassandra_columns.Boolean(default=False)
is_active = cassandra_columns.Boolean(default=True)
is_anonymous = cassandra_columns.Boolean(default=False)
is_authenticated = cassandra_columns.Boolean(default=False)
def __str__(self):
return self.email
def get_by_natural_key(self, username):
return self.get(**{self.USERNAME_FIELD: username})
objects = UserManager()
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = []
class Meta:
get_pk_field = 'userid'
db_table = "amf_user_authentication"
verbose_name = 'user'
verbose_name_plural = 'users'
def get_full_name(self):
'''
Returns the first_name plus the last_name, with a space in between.
'''
full_name = '%s %s' % (self.first_name, self.last_name)
return full_name.strip()
def get_short_name(self):
'''
Returns the short name for the user.
'''
return self.first_name
def email_user(self, subject, message, from_email=None, **kwargs):
'''
Sends an email to this User.
'''
send_mail(subject, message, from_email, [self.email], **kwargs)
When I tried to createsuperuser after done with sync_cassandra I am getting following exception:
Traceback (most recent call last):
File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "D:\py3sbpoc\env\lib\site-packages\django\core\management__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:\py3sbpoc\env\lib\site-packages\django\core\management__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\py3sbpoc\env\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, cmd_options)
File "D:\py3sbpoc\env\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 59, in execute
return super().execute(*args, *options)
File "D:\py3sbpoc\env\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(args, options)
File "D:\py3sbpoc\env\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 117, in handle
self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
File "D:\py3sbpoc\sbpoc\dashboard\models.py", line 43, in get_by_natural_key
return self.get({self.model.USERNAME_FIELD: username})
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, *kwargs)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\query.py", line 394, in get
clone = self.filter(args, kwargs)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\query.py", line 836, in filter
return self._filter_or_exclude(False, *args, *kwargs)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\query.py", line 854, in _filter_or_exclude
clone.query.add_q(Q(args, **kwargs))
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\sql\query.py", line 1253, in addq
clause, = self._add_q(q_object, self.used_aliases)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\sql\query.py", line 1277, in _add_q
split_subq=split_subq,
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\sql\query.py", line 1213, in build_filter
col = targets[0].get_col(alias, join_info.final_field)
File "D:\py3sbpoc\env\lib\site-packages\django_cassandra_engine\models\django_field_methods.py", line 251, in get_col
raise NotImplementedError(NOT_IMPL_MSG)
NotImplementedError: Method not available on Cassandra model fields
Defined Custom User Model for Cassandra based authentication:
When I tried to createsuperuser after done with sync_cassandra I am getting following exception:
Traceback (most recent call last): File "manage.py", line 15, in
execute_from_command_line(sys.argv)
File "D:\py3sbpoc\env\lib\site-packages\django\core\management__init__.py", line 371, in execute_from_command_line
utility.execute()
File "D:\py3sbpoc\env\lib\site-packages\django\core\management__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "D:\py3sbpoc\env\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, cmd_options)
File "D:\py3sbpoc\env\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 59, in execute
return super().execute(*args, *options)
File "D:\py3sbpoc\env\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(args, options)
File "D:\py3sbpoc\env\lib\site-packages\django\contrib\auth\management\commands\createsuperuser.py", line 117, in handle
self.UserModel._default_manager.db_manager(database).get_by_natural_key(username)
File "D:\py3sbpoc\sbpoc\dashboard\models.py", line 43, in get_by_natural_key
return self.get({self.model.USERNAME_FIELD: username})
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, *kwargs)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\query.py", line 394, in get
clone = self.filter(args, kwargs)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\query.py", line 836, in filter
return self._filter_or_exclude(False, *args, *kwargs)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\query.py", line 854, in _filter_or_exclude
clone.query.add_q(Q(args, **kwargs))
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\sql\query.py", line 1253, in addq
clause, = self._add_q(q_object, self.used_aliases)
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\sql\query.py", line 1277, in _add_q
split_subq=split_subq,
File "D:\py3sbpoc\env\lib\site-packages\django\db\models\sql\query.py", line 1213, in build_filter
col = targets[0].get_col(alias, join_info.final_field)
File "D:\py3sbpoc\env\lib\site-packages\django_cassandra_engine\models\django_field_methods.py", line 251, in get_col
raise NotImplementedError(NOT_IMPL_MSG)
NotImplementedError: Method not available on Cassandra model fields