Problems with custom model user in Django 5.0

I’m pretty new in this world of django apps so I’m still learning how the things works.

I’m trying to do a CRUD for my work, so we can register some things like clients info, ours tasks, assistance… etc. In an entuthiastic and young learning spirit I decided to make a custom user model in order to be able to add a profile picture of the users of this app. I was part succeded while I was able to add users and edit its info in the app but some problems came to me later:

  1. I can create users from Django admin pannell but then this users can’t logging neither the app nor the admin pannell even when I created this with the superuser and staff marks on.

  2. I can make a relation between my users and groups of the model auth.Group.

To solve 1) or at least to live with it, I found I can create users with the terminal and the command ‘createsuperuser’ and remove permissions later altought I suspect this ‘removing permission’ don’t work at all. But for the purpose of this project I tought it wold be fine anyway at least for now.

I include this lines in my custom_user_model_apps’ views.py of my django project:

...
from django.contrib.auth.models import AbstractUser
...

...
class User(AbstractUser):
    image = models.ImageField(upload_to=profile_picture_path, blank=True)
    birthday = models.DateField(null=True, blank=True)
    dark_mode = models.BooleanField(default=False)
    telephone = models.CharField(
        max_length=20, null=True, blank=True, default=None)
...

And in my project settings.py:

INSTALLED_APPS = [
...
my_app's_name.apps.AsistenciasConfig'
...
]

AUTH_USER_MODEL = 'my_app's_name.User'

I’m using this funciton to make the login part:

def Log_in_function(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)

        if user is not None:
            login(request, user)
            return redirect('home')
        else:
            messages.error(request, 'Wrong username or password.')

    form = AuthenticationForm()
    return render(request, 'core/login.html', {'form': form})

And I’m obtaining the ‘Wrong username …’ message in my localhost and the admin panel.I’m gessing the ‘authenticate’ function is pointing some way to the users of ‘auth.user’ and not to my ‘my_name_app.user’ so when it tries to authenticate a giving username and pasword it fails because there is nothing there…

  1. Advancing with my project I thought it would be good filter some actions deppending on who is logged in, so I try to use django groups and this way I discovered that seems to be that the model Group that Django itself creates is completely separated of my custom user model ‘User’. This way, even when I can create groups in django admin panel I can’t assigning this to my users and all my user are part of all the groups I created (maybe because they where created with the command ‘superuser’) even when groups arrived much later than users.

I tried to add a ‘group’ field with both, ‘ForeingKey’ and ‘ManyToMany’ relations to ‘auth.Group’ from my user model but this just add a field in my user creation/editing form parrallel to the Group of auth.Group and still can’t assigning a particular group to a given user. So, to this point I’m pretty lost of what can I do to solve this issue.

Any idea?

New contributor

Ramiro Latigano is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật