Answer the question
In order to leave comments, you need to log in
Is it possible to combine data from multiple tables into a model in django?
The data model is represented by a set of properties stored in different tables and different databases.
That is, several tables store the same set of objects.
Is it possible to stir up such a tricky model, with a tricky manager and a tricky queriset, so that it looks (for the djangoadmin, at least) like a model stored in one virtual table (outer join of the original ones).
From another point of view: the model is stored in a distributed relational database.
The question is rather theoretical, but it seems interesting.
In my particular application, there are only 4 independent fields and, apparently, it will be easier to make one master table to store all the properties, stuff it into the rest of the bases in pre / post_save, and hope that the data does not get out of sync.
Answer the question
In order to leave comments, you need to log in
Look towards InlineModelAdmin
Example
from django.contrib import admin
from catalog.models import Item, ItemPhoto, ItemParams
class ItemPhotoInline(admin.TabularInline):
model = ItemPhoto
extra = 1
class ItemParamsInline(admin.TabularInline):
model = ItemParams
extra = 1
class ItemAdmin(admin.ModelAdmin):
list_display = ('name', 'price', 'oldprice', 'show', 'available', 'sort', 'create', 'update')
list_display_links = ('name', 'price')
list_filter = ('show', 'available', 'offer')
search_fields = ['name']
list_editable = ("sort",)
fieldsets = (
(u"Настройки", {'fields': ('category', 'offer', 'show', 'sort', 'ref_url')}),
(u"Общее", {'fields': ('name', 'url', 'title', 'vendor', 'picture', 'thumbnail', 'price', 'oldprice', 'text', 'subtext')}),
(u"XML", {'fields': ('xml_id', 'xml_original_id', 'xml_category_id')}),
)
inlines = [ItemPhotoInline, ItemParamsInline]
admin.site.register(Item, ItemAdmin)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question