django-users

Django: How can i get the logged user outside of view request?

北慕城南 提交于 2019-12-19 04:51:17
问题 I have a class method (outside of a view) who needs the logged user's information. How can i retrieve the logged in user without passing the request to the method? Unfortunately i can't find nowhere a nice solution and it's not logical just not exist such a way to do it, because Django should store somewhere the logged in user. Otherwise (i believe) it would be impossible to use @login_required decorator from django.contrib.auth.decorators . Right? So if it's not possible why it's not? Why

How do I inline edit a django user profile in the admin interface?

怎甘沉沦 提交于 2019-12-17 21:52:46
问题 If you want to store extra information about a user (django.contrib.auth.models.User) in Django you can use the nifty AUTH_PROFILE_MODULE to plug in a "profile" model. Each user then gets a profile. It's all described here: http://docs.djangoproject.com/en/dev/topics/auth/#storing-additional-information-about-users http://www.djangobook.com/en/1.0/chapter12/#cn222 Now, let's say I have created an application called accounts with a model called UserProfile and registered it as the profile

Add image/avatar field to users in django

假装没事ソ 提交于 2019-12-17 10:12:24
问题 I want that each user in my website will have an image in his profile. I don't need any thumbnails or something like that, just picture for each user. The simpler the better. The problem is I don't know how to insert this type of field to my user profile. Any suggestions? 回答1: You need to make a form that has a clean method that validates the properties you're looking for: #models.py from django.contrib.auth.models import User class UserProfile(models.Model): user = models.OneToOneField(User)

Django UserCreationForm for custom model is outputting 3 password fields password, password1, and password2

↘锁芯ラ 提交于 2019-12-14 04:22:05
问题 Ok, so I have a user registration form based on AbstractUser that replaces the Django model in my settings.py, the model only adds a couple of fields I needed for info on the users, when I tested the registration form the user did not get created, I debugged and found that both last login and date joined where required so I set them as hidden inputs with value of {% now "SHORT_DATE_FORMAT" %} that solved the first two errors however there is a third error that says the field password is

django-userena views.py and user registration issues

╄→гoц情女王★ 提交于 2019-12-13 18:06:41
问题 django-userena does not have a views.py file. It uses instead html files, i would like to use this views.py instead of the html files, because i want to add some other features, like a file uploader. I'm having a hard time implementing apps like django-jquery-file-upload The second question is how to activate the user's account automatically after that he confirms his email. 回答1: The first thing that i would like to do is get rid of the html files and replace them with this views.py, django

Extending the Django 1.11 User Model

久未见 提交于 2019-12-13 15:23:38
问题 I am attempting to work out how to extend the Django user model to add information to a user. I can't seem to get it to work. What am I doing wrong? Is it okay to have foreignkeys within the same model I am extending in to? How do you create a superuser, or do you have to do it manually through the python manage.py shell ? Here's my code so far: class PersonModel(models.Model): user = models.OneToOneField(User, on_delete=models.CASCADE) firstName = models.CharField(max_length=50) lastName =

send mail to user for password_reset

允我心安 提交于 2019-12-13 08:36:55
问题 I am trying to implement password_reset (message sending to user for reset his password), but after writing email, nothing has send and the user is redirected to home... My view.py : ... from django.contrib.auth.views import password_reset, password_reset_confirm # Import the render shortcut to render the templates in response. from django.shortcuts import render # This view handles the password reset form URL /. def reset(request): return password_reset(request, template_name='le_site/reset

Django - Changing Auth username to Autofield breaks the code

梦想的初衷 提交于 2019-12-13 03:17:15
问题 I've an application where I need to change username field to Autofield . Use-case - I'am building an application where when the users will be created, usernames should be like CustomerID(integers) in banking applications. There are 2 ways of doing it:- 1) Have an id (PK), the default implementation of it. Copy the id , of the object and assign it to the username column, to allow users to sign-in via the id. Trade-offs Two duplicate columns. How would I call create_user function as it requires

Registration Form not submitting in Django

穿精又带淫゛_ 提交于 2019-12-13 00:07:26
问题 I am doing registration in django using a form with overriding save method. I am not having any error but not submitting form. Following is my code: Models.py: from django.db import models from django.contrib.auth.models import User class UserProfile(models.Model): user=models.OneToOneField(User) meta_keywords=models.CharField("Meta Keywords",max_length=255, help_text="Comma delimited set of keywords of meta tag") meta_description=models.CharField("Meta Description",max_length=255, help_text=

Django: Programmatically add Groups on User save

大憨熊 提交于 2019-12-12 09:08:20
问题 After a user is saved, I need to make sure that its instance is associated with a group by default. I have found two ways to achieve that: Overriding the model's save() method models.py: from django.contrib.auth.models import AbstractUser, Group class Person(AbstractUser): def save(self, *args, **kwargs): super().save(*args, **kwargs) to_add = Group.objects.get(id=1) # get_or_create is a better option instance.groups.add(to_add) Capturing a post_save signal: signals.py: from django.conf