One of the best tutorial i've ever seen on YT. You have a gift to teach man👌. 1. But why in Django in models (11:53) we use class variable without `self`? 2. 11:55 Why You use `{% if request.user.is_authenticated %}` and in another tutorial You use {% if user.is_authenticated %}`. What's the difference?
Thanks a lot! 1. We define model classes without 'self' because these are class attributes and not instance attributes. 'Self' you would use when defining a method inside a class. 2. they are the same, the difference is what object you are accessing. The request object is loaded to every template and we can access the user from there, or we can use the "user" variable, which is loaded also automatically to every template, and represents the logged-in user. That's why you should not name a variable "user", that would override this variable. But which version you want to use is up to you. Without "request." is simpler.
Okay will try this tomorrow because it suck azz to deal with styling for django allauth (i have skill issue reading the doc maybe idk), and here you make things easy af
Minor suggestions: 1) Get rid of try except in profile avatar property. I changed it to this: @property def avatar(self): if self.image: return self.image.url return static("images/avatar.svg") 2) Add hyphenation to frontend for profile info. If you type a very long word it is not split into several lines.
@@ajudmeister it seems that it has to follow some quirky rules to work properly, it works if you type "Kraftfahrzeughaftpflichtversicherung Kraftfahrzeughaftpflichtversicherung Kraftfahrzeughaftpflichtversicherung Kraftfahrzeughaftpflichtversicherung" but it doesn't if you try "Coooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool". break-all did help, changed it to {{ profile.info|linebreaksbr }}
darn you shorts for converting me... and all hail the algorithm for putting this in front of me. I was looking for a simple oauth integration with django!
awesome tutorial sir. Can you do a video on how to deploy in aws? 🤕[ django, tailwind, postgresql, ci/cd ] . There is no good video available online on the topic .Topic could be "How to deploy django website with CI/CD in aws". Please sir make a video. You have an incredible ability to simplify complex topics. 🧡🧡🧡
Also noticed that there is a little inconsistency with User model/admin.py. When we login/signup email field is required but it is optional if you create object yourself or through django admin (it's not even present in the Add form).
@@ajudmeister I made custom user model inhereted from AbstractUser. from django.contrib.auth.models import AbstractUser class User(AbstractUser): email = models.EmailField(unique=True) USERNAME_FIELD = 'email' REQUIRED_FIELDS = ['username'] Added custom model to settings: AUTH_USER_MODEL = "users.User" Added email to add userform in admin: from django.contrib.auth.admin import UserAdmin as BaseUserAdmin @admin.register(User) class UserAdmin(BaseUserAdmin): add_fieldsets = ( ( None, { "classes": ("wide",), "fields": ( "email", "username", "password1", "password2", ), }, ), ) And replaced everywhere from django.contrib.auth.models import User to from django.contrib.auth import get_user_model User = get_user_model()
Thanks, this is great, but there may be a bug, or I missed a step. If you go to Login, then select "sign up" from the hyperlink after a new user is created they redirect to home rather than profile creation. To fix it update the login.html href --> href="{% url 'account_signup' %}?next={% url 'profile-onboarding' %}"
Thank you, well spotted! I made a copy of the login.html file from the allauth templates and added the "next" parameter. I also deleted the {% blocktrans %} tag, that was causing an issue there. Cheers!
Thank You. That was great great great ♥. Sir, Do you plan to teach multiple user types example: [teacher, admin, student, parent] ? Best Wishes and Good Luck
Encountered a problem with {% if user.emailaddress_set.first.verified %} in templates/users/profile_settings.html. Had to change first to last ({% if user.emailaddress_set.first.verified %} to show the correct status. Maybe some recent updates to Allauth changed ordering. UPD: Turned out it doesn's matter because there should be only one EmailAddress object. But somehow I had two (initial and changed). Tried to replicate it again but everything's working as intended.
Are you using allauth? With allauth a user could have more email addresses associated with the same user, thats why I am using .first because it gives me back a list, but should only have one object in it. If you got somehow two, maybe the save method didn't update the email but created a new object instead, then the last might be verified.
Great video! Currently looking into how to use social login with management and connecting accounts, and 2FA with Authenticator apps but can't find anything on TH-cam :(
Thanks. Will put social login and 2FA authentication in the list. allauth has documentation for the different logins, but haven’t tried them out myself yet.
i really like alpine because it's easy to use for many often used behaviours. hyperscript is still a bit obscure to me, if I need some custom javascript I might opt to use vanilla javascript instead if I had to choose.
Hello, as I mentioned in the intro this video is a bit advanced and not for absolute beginners. You should check out my backend tutorial series if you are new to django as I explain the concept there in detail. All the best
As always, I enjoy your great videos. Thanks for the great effort you always put into your work
One of the best tutorial i've ever seen on YT. You have a gift to teach man👌.
1. But why in Django in models (11:53) we use class variable without `self`?
2. 11:55 Why You use `{% if request.user.is_authenticated %}` and in another tutorial You use {% if user.is_authenticated %}`. What's the difference?
Thanks a lot!
1. We define model classes without 'self' because these are class attributes and not instance attributes. 'Self' you would use when defining a method inside a class.
2. they are the same, the difference is what object you are accessing. The request object is loaded to every template and we can access the user from there, or we can use the "user" variable, which is loaded also automatically to every template, and represents the logged-in user. That's why you should not name a variable "user", that would override this variable. But which version you want to use is up to you. Without "request." is simpler.
@@ajudmeister But we use instances of a class in a project not class itself. Is that correct?
Thank for this. Keep making htmx and django
Super great content mate. Thanks, and respect! :)
I appreciate the feedback. thanks!
Okay will try this tomorrow because it suck azz to deal with styling for django allauth (i have skill issue reading the doc maybe idk), and here you make things easy af
:) yea styling allauth can be a bit tricky as it comes with all his own templates.
Thank you so much for this. It helped me a lot with my project
Minor suggestions:
1) Get rid of try except in profile avatar property. I changed it to this:
@property
def avatar(self):
if self.image:
return self.image.url
return static("images/avatar.svg")
2) Add hyphenation to frontend for profile info. If you type a very long word it is not split into several lines.
Awesome! Thanks a lot. Updated.
@@ajudmeister tried it but even with hyphens-auto long word in info is still not split and goes as far as it can go as if there was no limit to width.
@@twiceasviewtiful hmm, when i tried the word was split with hyphens-auto. maybe need to add break-words aswell
@@ajudmeister it seems that it has to follow some quirky rules to work properly, it works if you type "Kraftfahrzeughaftpflichtversicherung Kraftfahrzeughaftpflichtversicherung Kraftfahrzeughaftpflichtversicherung Kraftfahrzeughaftpflichtversicherung" but it doesn't if you try "Coooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooool".
break-all did help, changed it to
{{ profile.info|linebreaksbr }}
I like before I watch, I am sure this will be great.
Risky …
darn you shorts for converting me... and all hail the algorithm for putting this in front of me. I was looking for a simple oauth integration with django!
All hail the algorithm then! I am glad you find it useful.
@@ajudmeister so reading the docs, it would be pretty easy to add in google oauth to this, right?
@@la009895 yes it should be, but haven’t done it yet myself.
@@ajudmeister I smell a new short. How to add oauth to your project quickly!
@@la009895 lol, we will see. maybe it takes 2 seconds, no idea yet
Thanks Andreas,, Amazing Tutorial,, Take love
He's the GOAT!!
Thanks :)
This is really great. Thanks for sharing.
Wonderful new video, thank you for the video.
Thank you for the template, very helpful
your videos are awesome you make any django-backend developer to a frontend developer :)
haha, you bet!
Great tutorial. Inconsistent use of terms "log out" and "sign out" (easily fixed).
Thanks! Yea, it’s always tricky to be consistent 😅
awesome tutorial sir. Can you do a video on how to deploy in aws? 🤕[ django, tailwind, postgresql, ci/cd ] . There is no good video available online on the topic .Topic could be "How to deploy django website with CI/CD in aws". Please sir make a video. You have an incredible ability to simplify complex topics. 🧡🧡🧡
Hi, yes I might do that. I am planning a docker series aswell, could combine it there. Thanks for suggestion and feedback
Also noticed that there is a little inconsistency with User model/admin.py. When we login/signup email field is required but it is optional if you create object yourself or through django admin (it's not even present in the Add form).
Do you mean when the admin creates a new object it should tell him the email is required? How would you go about this?
@@ajudmeister I made custom user model inhereted from AbstractUser.
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
email = models.EmailField(unique=True)
USERNAME_FIELD = 'email'
REQUIRED_FIELDS = ['username']
Added custom model to settings:
AUTH_USER_MODEL = "users.User"
Added email to add userform in admin:
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
@admin.register(User)
class UserAdmin(BaseUserAdmin):
add_fieldsets = (
(
None,
{
"classes": ("wide",),
"fields": (
"email",
"username",
"password1",
"password2",
),
},
),
)
And replaced everywhere
from django.contrib.auth.models import User
to
from django.contrib.auth import get_user_model
User = get_user_model()
I loved it, keep going
will you make a video on django social login with google and facebook
@@adarsh6766 yes, on the list
Awesome video! thank you!
Thanks for the video!!!
You are welcome :)
Thanks, this is great, but there may be a bug, or I missed a step. If you go to Login, then select "sign up" from the hyperlink after a new user is created they redirect to home rather than profile creation. To fix it update the login.html href --> href="{% url 'account_signup' %}?next={% url 'profile-onboarding' %}"
Thank you, well spotted! I made a copy of the login.html file from the allauth templates and added the "next" parameter. I also deleted the {% blocktrans %} tag, that was causing an issue there.
Cheers!
Thank You. That was great great great ♥.
Sir, Do you plan to teach multiple user types example: [teacher, admin, student, parent] ?
Best Wishes and Good Luck
Thank you! I assume you are talking about different permission settings for different groups. I might integrate it in a future project, yes.
Encountered a problem with {% if user.emailaddress_set.first.verified %} in templates/users/profile_settings.html. Had to change first to last ({% if user.emailaddress_set.first.verified %} to show the correct status. Maybe some recent updates to Allauth changed ordering.
UPD:
Turned out it doesn's matter because there should be only one EmailAddress object. But somehow I had two (initial and changed). Tried to replicate it again but everything's working as intended.
Are you using allauth? With allauth a user could have more email addresses associated with the same user, thats why I am using .first because it gives me back a list, but should only have one object in it. If you got somehow two, maybe the save method didn't update the email but created a new object instead, then the last might be verified.
@@ajudmeister Yeah. Turned out I had two because I changed email once before writing post_save signal part that's why a new object was created.
thanks for the vid
Great video! Currently looking into how to use social login with management and connecting accounts, and 2FA with Authenticator apps but can't find anything on TH-cam :(
Thanks. Will put social login and 2FA authentication in the list. allauth has documentation for the different logins, but haven’t tried them out myself yet.
@ajudmeister thank you! 😊
Very nice, thanks. Can you plz add tailwind configuration with the django-tailwind package?
i will make another deep dive into tailwind when Tailwind v4 is out.
by the way, i see that you use alpineJS and hyperscript as well, my question is which of them both would you prefer and why?
i really like alpine because it's easy to use for many often used behaviours. hyperscript is still a bit obscure to me, if I need some custom javascript I might opt to use vanilla javascript instead if I had to choose.
Good thank
is this project use ORM? and i wonder if instead of using orm, can we use raw sql🤔
Yes, it is using Django’s ORM system, however you can write raw SQL queries aswell if you prefer.
Why can't you explain what are you writing? This is for beginners, so please explain how is this working
Hello, as I mentioned in the intro this video is a bit advanced and not for absolute beginners. You should check out my backend tutorial series if you are new to django as I explain the concept there in detail. All the best
would be very helpful if you could point out how can we load allauth with another language as I believe it supports multi language templates.
Django indeed supports multi language templates, however I have not worked with them yet, so I can only refer to the official Django documentation.
@@ajudmeister thanks Andreas I managed to get them working after a bit of back and forth.