Want to make an action - django

I have an django site for new articles , in which multiple user write articles.
I want to make an action for selecting a user , so that If I choose a particular user , I can only see its updation/insertion in admin site.

If updation/insertion is part of a model that has an foreign key to USER model, then just write an admin-inlline to show a list of them in the user page below all other fields

Related

How to extend django admin user model with new fields?

I want to add more fields to django built in admin user model. How can I achieve it?
Actually , There are three users on django server, student , teacher and parent. And by adding a 'role' field to user model, I can identify which type of user is log-ged in . So how can I extend the model field.
I'm expecting to identify different role of users in login.

Django Many To Many field with filter

I am trying to add a filter to my ManyToMany field.
I have a model User and a model Notification. Notification is connected with User by a ManyToMany field. I want to be able to send a Notification to all users that are for example located in Bulgaria or filter them based on another property in the user model which is not predefined(i.e. The person who creates the Notification does not know pre-creation the filter field).
I tried using raw_id_fields for User in Notification admin page. I can then chose and filter Users I want to add based on filters in the Model but I can only choose one user at a time and if I have to add, for example 10k users this can be quite inconvenient.
I want to be able to either use raw_id_field and select multiple instances at once, or add some field filtration to filter_horizontal or I don't know.
I believe what your looking for is this:
list_filter = ['user__located']
That will let you filter Notifications by the located attribute on Users.

How to define type of 3 users(Teacher, Parent, Student) and login them

I am gonna create an electronic_diary for school. How to define type of 3 users(Teacher, Parent, Student) and login them.
your question is very generic, so here is a generic answer, it will help you get started:
there are two solutions:
create a user profile model and connect it to existing django user model, add user_type field there doc
create your own user model for django and add user_type field there doc
then on login and queries get user_type and change query/forms/permissions based on that
read the whole doc on this page it's good!

Custom Django Authentication

I have an model named Customers(username,password ..etc) and also an model named User(username,password...etc).
I want to create two different APIs with different authentication.
One should authenticate with the User username,password
and the second should authenticate using the Customers username,password.
Any idea on how can I do this?
Thank you!
I suggest the following options:
1.
I am assuming User model is the "real" user of your app. If this is true use the django's default User model class. It will work out of the box.
For the Customer model, make it inherit from AbstractBaseUser, this will give you password functionality out of the box and you can add other fields as per your need.
Now you can create 2 different urls for login. 1 url for user which checks in the User model and the other for the customer model. This avoids any confusion for everyone.
If you prefer a single url, you have to mention the model class along with username and password to know in which table to verify them.
2.
Create two profile models: UserProfile and CustomerProfile
Each will have a one to one relationship with the django's default User model.
Basically a User can have the profile of a "real" user or of a customer.
In this case when you are creating any User you have check if you want to attach a UserProfile or a CustomerProfile.
In this case it makes sense to just use a single login url. From the user's login information you can first fetch the user from the User table and then check if it is a customer or not by running a query in the CustomerProfile table.
I recommend you to use the django.contrib.auth.user class for your classical authentication. You can either inherit from that class or add a OneToOne relation to your own model as follows
from django.contrib.auth.models import User
class YourUser(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
For the rest of your question you should add some more details and even some pieces of your code.

How to modify the way a ForeignKey field is rendered in a Django admin page to avoid browser crash?

I have a Customer model which contains a ForeignKey to a Contact model.
I have over 100,000 contacts in my DB and when I load the admin page for a specific customer, the dropdown menu for the contact is getting populated with ALL of the contacts in the database. This has recently, due to its shear length, started causing my Firefox to crash while the admin page is loading.
Is there a way to either:
replace the field with an integer
field I can manually modify to the
contact ID when necessary
replace the dropdown menu with some
alternative input method which won't
crash the browser
remove this input
from the Customer admin page
altogether
Thanks!
You can do any of the either of things you want to.
Simplest solution is the exclude the field from the admin. Just say so in the admin class.
You can change the field to be text input and display it's primary key rather than the item itself, by including it in the raw_id_fields of the admin class.
You can also replace the standard dropdown widget with the Auto complete text field input. Use the implemented widget, or other equivalents. - This is probably the solution you like the best.
You can also override the formfield_for_foreignkey method on the Admin model to customize the queryset that gets displayed in the foreign-key dropdown. You may want to checkout my implementation for displaying only the current User's (or subdomain's) added entities.
Sounds like specifying the contact field in raw_id_fields in your admin.py entry for the relevant model would sort you out. Docs are here.
PS. Surprised (but not that surprised) that FF gives out before your database server tanks...