Replicating a new database without using manage.py
Hi all, I'm creating multi-tenancy capabilities for out back-end application and I need to create a separate database for every current tenant. Playing around with pg_dump and pg_restore, I noticed that a new restored PostgreSQL database is fully functional and I don't need to use the proper *makemigrations+migrate* procedure. Then I can log in into the admin interface of the Django app and delete all the extraneous data leaving just the one related to the tenant. Do you see any inconvenience in proceeding this way? Below the procedure I use (cleansed of host, port and user options): /usr/bin/pg_dump -Ft --no-acl --no-owner -f /tmp/dump.tar /usr/bin/pg_restore -n public -d /tmp/dump.tar Thank you very much. -- 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 post to this group, send email to django-users@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/af68cb61-01b4-44a0-9efc-faecb7c3f0fe%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
REST API social authentication
Hi all, I need to implement social authentication in my set of REST API. I did some googling and found sever modules, e.g. django-rest-framework-social-oauth2 social-auth-app-django django-rest-social-auth rest-social-auth Can you please recommend me a proper way to deal this? I'm quite a newbie in Django, so any advice and suggestions will be greatly appreciated! -- 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 post to this group, send email to django-users@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/e4f933b6-04e2-4f5a-bf7b-5fb1eaaa719b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Doubt about Custom User Model
Hi! I've read some examples about custom User Model. In all of them, it's suggested implement the class AbtractUser (in this case the app is called *users*) For instance, in this example https://wsvincent.com/django-custom-user-model-tutorial/ they do users/models.pyfrom django.contrib.auth.models import AbstractUserfrom django.db import models class CustomUser(AbstractUser): but then they say to include *users.apps.UserConfig*. Why? Where does it come from? Why not the class *users.apps.CustomUser* ? # djauth/settings.pyINSTALLED_APPS = [ ... 'users.apps.UsersConfig', ] Thank you very much -- 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 post to this group, send email to django-users@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/5bcb0c0a-c83f-4a67-97a7-325ef6ecc87b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Need help on how to proceed: django-rest-auth with custom user model
Hi all, I'm writing a backend in Django, I want to use *django-rest-auth*(1) to handle registration/email verification/social auth, the problem is that I need to distinguish between two different users: customer and professional My question: is it better to proceed making *django-rest-auth* working as it comes "out of the box" and in a second moment go back and customize the user modem or vice versa? Note that at the I don't have data to preserve, I can easily recreate the database. Any suggestion will be greatly appreciated! 1) https://django-rest-auth.readthedocs.io/en/latest/index.html -- 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 post to this group, send email to django-users@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/7172f781-b6e9-4326-90b4-b4964c8c3e0d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Update profile on login
Hi all, I'm trying to update the field "date_activation" the first time a user log in. This is the error I get when i try to run the code below *TypeError at /admin/login/ int() argument must be a string, a bytes-like object or a number, not 'ModelBase'* Any help would be really appreciated! class Profile(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) location = models.CharField(max_length=30, blank=True) birth_date = models.DateTimeField(null=True, blank=True) date_activation = models.DateTimeField(null=True, blank=True) @receiver(post_save, sender=User) def create_user_profile(sender, instance, created, **kwargs): if created: Profile.objects.create(user=instance) @receiver(post_save, sender=User) def save_user_profile(sender, instance, **kwargs): instance.profile.save() @receiver(user_logged_in, sender=User) def user_logged_in_callback(sender, user, request, **kwargs): Profile.objects.filter(user=User).update(date_activation=datetime.now) -- 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 post to this group, send email to django-users@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/237c6adf-1d2c-4ce7-b8d6-60a7d827833a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
Re: Update profile on login
Il giorno venerdì 9 novembre 2018 10:29:06 UTC+1, Michal Petrucha ha scritto: > > > Hi, > > Could you please post the full stack trace rather than just the final > error message? That would make it easier to help you. > > Cheers, > Michal > Sure, thanks! Environment: Request Method: POST Request URL: http://localhost:4000/admin/login/?next=/admin/ Django Version: 1.11.16 Python Version: 3.6.5 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'rest_framework', 'card', 'corsheaders', 'allauth.socialaccount', 'rest_auth', 'rest_framework.authtoken', 'django.contrib.sites', 'allauth', 'allauth.account', 'rest_auth.registration'] Installed Middleware: ['corsheaders.middleware.CorsMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware'] Traceback: File "/usr/local/lib/python3.6/site-packages/django/core/handlers/exception.py" in inner 41. response = get_response(request) File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 187. response = self.process_exception_by_middleware(e, request) File "/usr/local/lib/python3.6/site-packages/django/core/handlers/base.py" in _get_response 185. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 57. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/contrib/admin/sites.py" in login 393. return LoginView.as_view(**defaults)(request) File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in view 68. return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper 76. return view(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapped_view 149. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in _wrapper 67. return bound_func(*args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/decorators/cache.py" in _wrapped_view_func 57. response = view_func(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/utils/decorators.py" in bound_func 63. return func.__get__(self, type(self))(*args2, **kwargs2) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/views.py" in dispatch 90. return super(LoginView, self).dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/generic/base.py" in dispatch 88. return handler(request, *args, **kwargs) File "/usr/local/lib/python3.6/site-packages/django/views/generic/edit.py" in post 183. return self.form_valid(form) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/views.py" in form_valid 119. auth_login(self.request, form.get_user()) File "/usr/local/lib/python3.6/site-packages/django/contrib/auth/__init__.py" in login 161. user_logged_in.send(sender=user.__class__, request=request, user=user) File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py" in send 193. for receiver in self._live_receivers(sender) File "/usr/local/lib/python3.6/site-packages/django/dispatch/dispatcher.py" in 193. for receiver in self._live_receivers(sender) File "./card/models.py" in user_logged_in_callback 75. Profile.objects.filter(user=User).update(date_activation=datetime.now) File "/usr/local/lib/python3.6/site-packages/django/db/models/manager.py" in manager_method 8
Re: Update profile on login
Il giorno venerdì 9 novembre 2018 11:37:23 UTC+1, Michal Petrucha ha scritto: Found it. :) The error lies in the filter() call: > > Thank you very much. I fixed it using @receiver(user_logged_in, sender=User) def user_logged_in_callback(sender, user, request, **kwargs): Profile.objects.filter(user=user).exclude(date_activation__isnull=False ).update(date_activation=datetime.now()) > By the way, I suggest that you use django.utils.timezone.now() instead > of datetime.now; it's usually a good idea to use timezone-aware > timestamps. And side note, you need to call the function; > I will try it out, thanks. QuerySet.update doesn't accept callables. > Sorry, what does it mean? -- 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 post to this group, send email to django-users@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/4b45b5f0-84d9-4a62-8fc8-6f1f9e0312ad%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
How to access first_name ad last_name in extended User model
Hi all, newbie here! I cannot access self.user.first_name and self.user.last_name in my ClientProfile class, this is the error message: *Instance of 'OneToOneField' has no 'first_name' member* *Instance of 'OneToOneField' has no 'last_name' member* What am I doing wrong? class ClientProfile(models.Model): user = models.OneToOneField( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, ) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) created_date = models.DateTimeField(auto_now_add=True) modified_date = models.DateTimeField(auto_now=True) def __str__(self): return '{} {}'.format(self.user.first_name, self.user.last_name) ' class ClientProfile(models.Model): user = models.OneToOneField( settings.AUTH_USER_MODEL, on_delete=models.CASCADE, ) id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable= False) created_date = models.DateTimeField(auto_now_add=True) modified_date = models.DateTimeField(auto_now=True) def __str__(self): return '{} {}'.format(self.user.first_name, self.user.last_name) ' with this in settings.py AUTH_USER_MODEL = 'accounts.CustomUser' # Overriding the default User model -- 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/209748b5-e51a-49b5-b37d-d1caed08a62d%40googlegroups.com.