So where do we put business logic in Django? Here are 4 possible solutions:- Idea #1: Fat Models I believe that the “default” idea supported by Django documentation is to make your models “fat.” To put it colloquially, this approach suggests that if you don’t know where some of the code should go, and it somehow relates to the object (and what doesn’t?), then it’s best to put it in the model. Idea #2: Putting Business Logic in Views/Forms Another idea is to place business logic in forms or views. Though I’ve seen it being seriously suggested, I don’t think that putting business logic in forms, views, or serializers is a clean idea. Idea #3: Services Another commonly advocated idea is that it’s worth to add a separate layer of code called services between views and models. That is quite unusual in a vanilla Django system but some projects successfully employ that method. To read full article click on the Source link below.
Here is what the above code is Doing:
1. We are importing the User model from the django.contrib.auth.models module.
2. We are creating a new class called UserProfileInfo.
3. We are creating a new field called portfolio_site.
4. We are creating a new field called profile_pic.
5. We are creating a new class called Meta.
6. We are telling Django that we want to inherit from the User class.
7. We are telling Django that we want to add additional attributes to our User class.
8. We are telling Django that we want to add the portfolio_site and profile_pic attributes to our User class.
9. We are telling Django that we want to use the UserProfileInfo class to extend the User class.