I'm new in Django.I have to create staff user but distinct data between them of same model in django-admin.
Can i add new permission in User model and implement in default admin?
I have not idea about how to implement. i.e. i have 2 staff user, and add data in same model.
If staff-user-1 is login then show only his added data only (can not see data added by staff-user-2).
is possible in built-in django admin ?
Thanks!!!
Related
I want to create a system that has two type of user.
Normal users and coaches.
How can I separate users when they login in system.
I want to separate their dashboard after they logged in.
Should I create two model? one model for users and one model for coaches?
You can either use Django's built-in Groups feature, create a Coach group and check in your views if a user is part of that group. Or you extend AbstractUser by adding a boolean field is_coach (and set AUTH_USER_MODEL settings to your new User model).
Then you can check this flag in your views.
The more interesting question is if you want to store extra information (add extra functionality on the user level) for coach type users. If this is the case, you can make a so called Profile model Coach which you set in one-to-one relation with the User model (which should only serve authentication purposes). Then you can add extra fields in your profile model to store information relevant to coaches. The next question would be: what about students? Should students be able to enroll in courses?
Django - Models extension Vs User Profile
I want add some custom fields like following
1. ssn
2. is_manager
3. manager
I have 2 choices -
Extend AbstractBaseUser
OR
Create User profile based on signal and have OnetoOne field.
Which one is better, future proof, DB migration friendly and maintainable ?
The Django documentation answers this question in detail:
If you wish to store information related to User, you can use a OneToOneField to a model containing the fields for additional information. This one-to-one model is often called a profile model, as it might store non-auth related information about a site user.
In your case, the added fields do not seem to be authentication related, so your best bet is to use the user profile method. Substituting a custom user model is overkill for such purposes.
I want to every user who is staff be able to see one certain model of my app as it would be related to it.
Instead to overwrite the save function in that model to get every staff user and relate them to the instance of that model through a Forneign Key I want to modify the permissions of the staff users to allow them to see the instances of that especific model in the admin interface.
Any clues on how to do it?
Sounds like you need Object-level permissions. Take a look at django-guardian package https://github.com/django-guardian/django-guardian
As you know, when give a can_view permission to a staff user, that user can view entire fields and able to make changes in any fields if editable.
Is there any feature in Django to make some staff users to restrict to view change list but can't get in to record. I just want to make them use only actions in change_list that if I give specific permissions. Otherwise they must just see the list without doing anything.
I know there are options like customizing django admin template or override any admin template. But it takes to much time. I wonder if there is any solution without customize or override.
Hi im really a noob at django.
Can i ask if there is anyway to filter list by user group?
When creating a user at admin, there is also choice for creating groups. After assigning these user to certain groups, i have another model e.g. Staff where Staff information is provided and is linked to the user. So very Staff must be a user and also must be member of the group staff. I have already created a drop down menu at Staff Page for the list of users when creating a new Staff.
The problem is that i cant seem to figure out how the list of users shown at staff page can be filtered according to the user group and also assignment since it should be OnetoOne relation w/ the user. So users who been used or is already linked to a certain staff will not show in that list again when creating a new Staff.
Im thinking of using Staff.model.count()? to do that and == the user to Staff User Group. but where should i out in order to customize it? please help
You should write your own ModelAdmin, then unregister User and register User with UserAdmin with your custom behaviour. This way you can overwrite the queryset, forms etc.. Look at the ModelAdmin source code
class UserAdmin(admin.ModelAdmin):
# do stuff
admin.site.unregister(User)
admin.site.register(User, UserAdmin)