I've been learning Django over the past few months, and have been hard-pressed to find an easy explanation of models. These videos are incredibly helpful! I read your 'Two Scoops of Django' at the recommendation of a friend and learned tons of high-level principles and nitty-gritty best practices. Thanks a million, Daniel and fam!!
I love how you really can feel how proud he is of his family which makes this video much more meaningful to me on an emotional level - and also awesome coding tutorial, thanks!
What is the protocol of changing Uma to a spy? For instance, if you did it such that uma = uma_from_users --> and then uma.type = User.Types.Spy. What would be the elegant way of dropping the uma driver data from DriverMore?
I love that you didn't clip the cup spill. That was great. If I had to guess, you didn't want to use extra because of the ORM's method to add 'extra' sql to queries.
I'm just new. I try to do this concept of multiple user_types with specific user_profile before i watch your greate video, but not in proxy. but by OneToOne rel.. everthing are fine and great, but something happen. anyway,, on my apps user_type is a REQUIRED_FIELDS, to make sure that all authUser have specific class User_???_profile(models.Model) as 1to1 rel. per user(ABaseUser)........ sooooo glad you made this. may God bless you
Nice video thank you :) Can you please explain why you would choose this approach more than having a User Abstract class with all the properties shared by spy / driver. Then create Spy / Driver class by inheriting from User and add the specific property to each class ? Thanks !
I covered near the end of the video. Here are my concerns: 1. How many fields will you need to cover all different types of users? If you have 5 user types each with 10 special data fields that's a LOT of fields on the user table. (I've seen this happen) 2. Will the data be substantial enough in size to affect table performance (I've seen this happen too)? Turns out all modern databases are fast enough to handle the joins my solution creates. :)
Thanks for the video , great ideas and new approch ive learned from it , but i wonder in this case, what is the best approach when it comes to signup forms?
Thank you!! I will have to dig a little more about that property. Also did that approach would work in a multi-tenancy environment? Could you later talk about JSON: examples and escenarios. Thank you!! Keep the great work, finally great ending :-)
I don't understand what is the advantage of using a one to one model over removing the proxy true and adding the fields in the driver or spy class. The number of tables would be the same. I understand that you shouldnt add them to user, but why not in driver and spy? So the approach you describe is Abstract User -> User -> Driver (proxy=True) - onetoone DriverMore and the other approach Abstract User -> User -> Driver (not proxy)
This is really amazing to see you here, mr. Feldroy. And that was great news for me to hear that The two scoops of Django 3 is coming! There aren't many good resources to learn Django. So I do hope you will continue with tutorials like this one. A question: if we opt to use abstract model inheritance, how do we stay DRY? Let's say we have Product abstract model and a hell lot of children models. Writing serializers/views for each of them is definitely not something we want. We could use mapping and Content Types framework or something along these lines, right?
Thanks for producing these videos! I look forward to seeing more of them. You got me thinking after watching this video and the last one on proxy models. I would appreciate your thoughts. In a tenant type app, that has a lot of one to one models holding all the settings for each tenant in each of the related apps. They're created via signal when the tenant is created. Of course the other models in those apps have foreign keys back to the tenant model in the tenant app. After watching this video and the last one, would it be wise to just use proxy models that span across apps? Or would you recommend continuing with the one to one models in each app with signals to create the objects? Thanks for any thoughts and keep up the great work!
Remember, proxy models are just different representations of tables. They don't store any new data. Think of them as views. With that in mind, if using just one database to control tenancy, I would build storage normally and just use Proxy models to show data differently. If using multiple databases, the same applies. Then again, I haven't used Proxy models in a multi-tenant design. So my observation is based on ZERO experience.
I think I'll just keep the simple one to one models in the various apps for now, otherwise my tenant model in its own app would have a hundred fields in it. The data doesn't necessarily need to be shown differently, it's mostly just looking up defaults for the tenants. But, I can definitely use the proxy models in another section they'll be perfect for. Thank you!
First: Thank you for the video. It was really helpful. Answer: Because "extra" and "more" are the two ends of the same rope. You are free to choose either one. :)
Hey dear it's a great tutorial. Can you explain how we can achieve this with django all-auth. Bcs multiple user, multiple sign-up forms. How we handle it. Can you make another tutorial for this?
Thanks for this video. From an OO perspective, a separate model class does seem better for separation of concerns, but these days I avoid going with OneToOneField due to the extra join, instead opting to put all the fields in one model as you described as an alternative. But I have bounced back and forth between those two practices, and keep changing my mind. Do you have any opinions on the extra join? One technique I've used instead is to add a property that returns a plain Python object out of e.g. the driver fields.
In 2010-2011 when I was worried about the performance hit of OneToOne fields, the late, great Malcolm Tredennick told me, "Relational databases are literally designed for joins. If a join begins to slow down enough for humans to notice, investigate and mitigate. Otherwise, don't optimize prematurely." I too have used the python object property you describe for user type fields. It works, but does take some extra coding.
Intro was really funny man👍 ... My question is what if we have 5 or more usertype in our project ? Also can We use these code manner in production also.. for a company websites..??
I've bought your new Django 3.0 book and i was reading the part about Model Managers. It is written that you should not replace the default manager, but instead create a custom one and add objects = models.Manager() before the custom one. Am I getting something wrong or is this just a shortcut for the video ? Thanks again.
For anyone getting a 'foreign key mismatch' error thrown, due to the OneToOneField referencing base user model. This is because of a pk error in your database. There may be a better way to get around it but I deleted my migrations and reran makemigrations & migrate.
There's no reason why you can't use both! You set user roles as you describe, then use proxy models and OneToOne fields to make it easier to navigate the models within your code base. In fact, this is how we do it. I'm just explaining a simpler version for now. Also, Django groups/users docs is sparse. Hmmm... maybe I'll submit a PR to fix that!
I've been learning Django over the past few months, and have been hard-pressed to find an easy explanation of models. These videos are incredibly helpful! I read your 'Two Scoops of Django' at the recommendation of a friend and learned tons of high-level principles and nitty-gritty best practices.
Thanks a million, Daniel and fam!!
I love how you really can feel how proud he is of his family which makes this video much more meaningful to me on an emotional level - and also awesome coding tutorial, thanks!
What is the protocol of changing Uma to a spy? For instance, if you did it such that uma = uma_from_users --> and then uma.type = User.Types.Spy. What would be the elegant way of dropping the uma driver data from DriverMore?
2024 and it's still usefull and up to date! Thanks a million!
I love that you didn't clip the cup spill. That was great.
If I had to guess, you didn't want to use extra because of the ORM's method to add 'extra' sql to queries.
Yes! That's i!
This channel has the best intro I've ever heard.
I was waiting for this content from months. Thanks a lot.
The intro music is just epic 🤩Go Daniel!
I'm happy you like it!
I was keep looking a solution since I didn’t know how to add fields to the proxy models. Thanks for your solution. I’ll use it in my project
I'm just new. I try to do this concept of multiple user_types with specific user_profile before i watch your greate video, but not in proxy. but by OneToOne rel.. everthing are fine and great, but something happen. anyway,, on my apps
user_type is a REQUIRED_FIELDS, to make sure that all authUser have specific class User_???_profile(models.Model) as 1to1 rel. per user(ABaseUser)........ sooooo glad you made this. may God bless you
Nice video thank you :) Can you please explain why you would choose this approach more than having a User Abstract class with all the properties shared by spy / driver. Then create Spy / Driver class by inheriting from User and add the specific property to each class ? Thanks !
I covered near the end of the video. Here are my concerns:
1. How many fields will you need to cover all different types of users? If you have 5 user types each with 10 special data fields that's a LOT of fields on the user table. (I've seen this happen)
2. Will the data be substantial enough in size to affect table performance (I've seen this happen too)?
Turns out all modern databases are fast enough to handle the joins my solution creates. :)
Thanks for the video , great ideas and new approch ive learned from it ,
but i wonder in this case, what is the best approach when it comes to signup forms?
Your video's are so useful Daniel, please keep them coming.
Thanks a lot 👍
More to come!
@@DanielFeldroy Awesome!
Needed this. Thanks man
Awesome video Daniel ! 👏
Glad you like it. Your latest videos have been awesome.
Thank you!! I will have to dig a little more about that property. Also did that approach would work in a multi-tenancy environment? Could you later talk about JSON: examples and escenarios. Thank you!! Keep the great work, finally great ending :-)
This video was really well made, Daniel. Thanks for doing it!
Great ! But how can i create user creation forms with those types
Looks like I need to make another video!
@@DanielFeldroy waiting for you ,sir
@@DanielFeldroy did you make video on it.
I don't understand what is the advantage of using a one to one model over removing the proxy true and adding the fields in the driver or spy class. The number of tables would be the same. I understand that you shouldnt add them to user, but why not in driver and spy? So the approach you describe is Abstract User -> User -> Driver (proxy=True) - onetoone DriverMore and the other approach Abstract User -> User -> Driver (not proxy)
I'm wondering the same thing . . .
Nice to hear from you. I like this approach. Different timezone, otherwise I would join twitch again. It's hard to do it now.
I'm trying to adjust which times I stream!
This is really amazing to see you here, mr. Feldroy. And that was great news for me to hear that The two scoops of Django 3 is coming! There aren't many good resources to learn Django. So I do hope you will continue with tutorials like this one.
A question: if we opt to use abstract model inheritance, how do we stay DRY? Let's say we have Product abstract model and a hell lot of children models. Writing serializers/views for each of them is definitely not something we want. We could use mapping and Content Types framework or something along these lines, right?
When did you add base_type? Can you please explain the logic, because i didn't see it in the first video :)
This is awesome! How would you create serializers for the rest auth framework with this approach?
Very helpful for us your tutorial.
very good as usual keep going short videos good knowledge
Thank you! I cut as much as I could to keep it concise and useful.
Thanks for producing these videos! I look forward to seeing more of them. You got me thinking after watching this video and the last one on proxy models. I would appreciate your thoughts. In a tenant type app, that has a lot of one to one models holding all the settings for each tenant in each of the related apps. They're created via signal when the tenant is created. Of course the other models in those apps have foreign keys back to the tenant model in the tenant app. After watching this video and the last one, would it be wise to just use proxy models that span across apps? Or would you recommend continuing with the one to one models in each app with signals to create the objects? Thanks for any thoughts and keep up the great work!
Remember, proxy models are just different representations of tables. They don't store any new data. Think of them as views.
With that in mind, if using just one database to control tenancy, I would build storage normally and just use Proxy models to show data differently.
If using multiple databases, the same applies.
Then again, I haven't used Proxy models in a multi-tenant design. So my observation is based on ZERO experience.
I think I'll just keep the simple one to one models in the various apps for now, otherwise my tenant model in its own app would have a hundred fields in it. The data doesn't necessarily need to be shown differently, it's mostly just looking up defaults for the tenants. But, I can definitely use the proxy models in another section they'll be perfect for. Thank you!
Is it possible to create a Spy and add info to the 'SpyMore' table in the same request?
Can u make us a video for custom Django Field with Json approach, since it's much extra work, thx.
Question: Why did I use "more" instead of "extra"?
"more" is meaningful to "required", "extra" denotes to "optional".
First: Thank you for the video. It was really helpful.
Answer: Because "extra" and "more" are the two ends of the same rope. You are free to choose either one. :)
can I user Profile instead of more and extra? for example SpayProfile() DriverProfile()
Hey dear it's a great tutorial.
Can you explain how we can achieve this with django all-auth. Bcs multiple user, multiple sign-up forms. How we handle it. Can you make another tutorial for this?
Thanks for this video. From an OO perspective, a separate model class does seem better for separation of concerns, but these days I avoid going with OneToOneField due to the extra join, instead opting to put all the fields in one model as you described as an alternative. But I have bounced back and forth between those two practices, and keep changing my mind. Do you have any opinions on the extra join?
One technique I've used instead is to add a property that returns a plain Python object out of e.g. the driver fields.
In 2010-2011 when I was worried about the performance hit of OneToOne fields, the late, great Malcolm Tredennick told me, "Relational databases are literally designed for joins. If a join begins to slow down enough for humans to notice, investigate and mitigate. Otherwise, don't optimize prematurely."
I too have used the python object property you describe for user type fields. It works, but does take some extra coding.
Thanks very nice video
I don't get it, you are still using OneToOne relationship, so what is the use of the proxy model?
Intro was really funny man👍
... My question is what if we have 5 or more usertype in our project ? Also can We use these code manner in production also.. for a company websites..??
great work, but when I tried more django gave an error : SQLite does not support JSONFields.
Does anyone having error in def more(self) function when accessing user.more ? I am having AttributeError: 'User' has no attribute 'usermore'
the best of the best
thank you
I've bought your new Django 3.0 book and i was reading the part about Model Managers. It is written that you should not replace the default manager, but instead create a custom one and add objects = models.Manager() before the custom one. Am I getting something wrong or is this just a shortcut for the video ? Thanks again.
Shortcut for the video
@@DanielFeldroy so we shouldn't do it the way you do in the video?
For anyone getting a 'foreign key mismatch' error thrown, due to the OneToOneField referencing base user model. This is because of a pk error in your database. There may be a better way to get around it but I deleted my migrations and reran makemigrations & migrate.
hahahahaha the last second 😅
How to authenticate the user when you have multiple types of users
It's still hard for me to find why user types are better than a user role permission approach.
There's no reason why you can't use both!
You set user roles as you describe, then use proxy models and OneToOne fields to make it easier to navigate the models within your code base. In fact, this is how we do it. I'm just explaining a simpler version for now. Also, Django groups/users docs is sparse.
Hmmm... maybe I'll submit a PR to fix that!
Also... Django user/roles are kinda more low-level access intended, instead of app business level (at least Django docs explain them as is)
user auth please!
Why not simply create a one to one Spy and Diver model? I'm just seeing the proxy models as redundant
goood☑☑