Registering a dummy model in Django admin to control multiple models data - django

Is it possible to register a dummy model (Does not exist in db) that will display data from multiple models in one page?
Maybe just list all objects and when use click on one, a new webpage is opened with details of the clicked on objects? Which is usually this view:
admin:{app_name}/{model_name}/{object_id}/change

The closest standard solution to what you want are Django inlines:
https://docs.djangoproject.com/en/3.0/ref/contrib/admin/#using-generic-relations-as-an-inline
I fail to see how you could create a model not present in the db.

Related

How can I implement authentication in Django

I am new to Django.
I am going to build simple register and login fullstack application by using React and Django.
My problem is when I received register request with form data.
Is it ok to create custom table for users?
I am going to create another table related to user table.
So in that case, there must be id in the users.
That's why I am going to create custom table.
Please help me it is good practice.
You can abstract from AbstractBaseUser and then you can customise the user model and to specify it in your settings file.
Please see the django documentation here:
https://docs.djangoproject.com/en/4.1/topics/auth/customizing/#substituting-a-custom-user-model
In Django you can link between multiple table by different relationships depends on what you want like:
OneToOne
ForeignKey
ManyToMany
And by default when you create a model django create a pk field it is ID for table, you can make another field as a primary key for model
When you use one of those relationships django by default use model id to link between them
and you can also create a custom user model to use it
Good luck

Django Admin LogEntry: how it works in non admin actions?

I am having some struggles how does exactly django.admin.LogEntry objects are created.
Consider the following scenario:
I have a bunch of functions which take a csv file with data that allow me to create multiple objects at one call (just iterate through the file, use the data and if data in given row is correct: create a Model instance). I want to make sure that that each of that creation will be logged.
The question is: django docs are not very descriptive on how does LogEntry works and I am not sure if such actions (not taken in the admin panel itself) will be logged there. Also: will the LogEntries be created for the related objects or I have to trigger them manually?
Does anybody got any experience with such scenarios and can share thoughts about it?
The LogEntry model is in the Admin package and only used by Django admin by default. It is used in the admin layer and not model layer when saving objects. if you want to use it outside the admin, then you will have to manually create the entries yourself. That also means the admin will likely display entries of changes made by normal users so you have to think about how you want the entries displayed

How do we change Field Names in our existing Users table in django

I am trying to Edit Users Table in Django. I am using Users Table to login or register a users. I have to add a new field name Role in that Table but i can't find any option to edit that existing table in admin section.
i just try to field some files to field out where the code of that existing Table is but did't get it.
is there any way to Edit the Table or I have to Create a New Table and have to create a new method of registration.
i am not expert so it's hard to me understand things.
Well first, the Django admin interface it's just for performing CRUD operations over already existing models, you are not able to change in any way the database tables (at lest not using the "out of the box features") using the admin interface.
Said that in order to do what you want to do, with any model (not just User), you should:
Add the field to the model.
Instruct the admin interface to list this fields along the others.
Now the user model is kind of a special model here so I'll recommend a couple of readings you should complete before go forward with the model User customization.
References (User customization): Substituting a custom User model, Extending the User model.
And for the admin interface ...
Reference (admin interface): ModelAdmin options, special attention here to list_display

How to retrieve data from DB without rerunning the server? (Django)

so I have multiple apps for my website; one to register, one to view a map with the users locations plotted on, and one to view the users' profiles. But those three apps need access to the same model, namely: User. (On the register page it gets created and added to DB, the map page needs its hometown in order to locate it on the map, and the profile pages also need it obviously). But whenever I add a new user on the admin page, I first have to rerun the server in order for it to appear on the map. Beforehand when the model was defined in just one app, I just needed to refresh the page to see the change. I have created the User model in the Register app and redirected to it in other apps like this:
class Meta(models.Model):
db_table = 'register_User'
Why doesnt the template retrieve the up to date data without restarting the server?
I hope u can help out
The way you are using the Django ORM is not correct.
You should not use the Meta in a models.Model class to reference a table in order to be able to access it.
If you need a model from a different app, just import it like this:
from user.models import User
And then you can use it in your views or models.
For a better understanding on how the Django ORM works, i recommend the Django tutorial or the models.Model reference pages.

Django admin: two change lists on the same page

I am trying to make an overview page for one of my models I have read through all of http://www.djangobook.com/en/1.0/.chapter17/ and understand how I can add my own custom views for a model to the django admin.
What I am currently trying to do is add multiple filtered change lists (presenting some child models) onto my "overview" page for the model. In these I would like to be able to make use of some of the admin features such as editable fields or actions.
Does anyone have some pointers on how I can best get started with this.
Check this out
He created a proxy model for the original model to avoid the conflict. You can create a new model admin or inherit the old ModelAdmin(as shown in the link)