I want to create a model that doesn’t map to a database table. Instead, stays in memory as a python object.
Actually, this model is supposed to represents normalised data from many other table-mapped models.
The other models store data which can be edited multiple times in a single day. Because of these multiple edits, I don’t want a table-mapped-model that performs normalisations/calculations and stores them in a database as, this stored data can go out of date right away.
Every time this normalised model is accessed (via admin), I want it to perform the normalisations on data from the other models from scratch (So that it can show the most up to date data) and behave just like a normal model would under admin like Showing the list view and a detailed view for each row.
Edit after Shintoist’s answer:
@Shintoist Thanks for the clearing things out and providing a usable approach. I have just implemented it but hitting a small wall in the end 🙂
@skirmantas: Yes, the calculations are in a separate object. This object is being passed into the custom views.
Problem: One problem is that under admin.py, I have created an modeladminclass for this object(which doesn’t inherit models.Model) so my custom views can overide the changelist view and changeview.
I then use admin.site.register() to register this model-like class and the modeladmin. But, since this model is not a django model at all (as it is an independant python object in memory) admin.site.register() throws a ” ‘type’ object is not iterable” error. I don’t want to use the url.py instead of admin.py as it’s meant for the frontend while Im trying to overide the backend-admin.
hmmm. Thanks for your help everyone. The solution I have come up (with your help ofcourse) is as follows:
I have two custom templates:
Under views.py:
Under the main django urls.py:
As you’ve already noticed, I had to insert url patterns to my url.py file. I don’t know if thats the best way to do it, as I reckon, the url.py file is not meant for admin related pages. It’s only for the site frontend.