W
W
warkb2019-05-22 16:09:21
Django
warkb, 2019-05-22 16:09:21

How to edit entities referencing element from TabularInline in Django admin?

There is an admin page for the car entity. On the same page, you can add and edit the Machine Dimensions entity. Here's what it looks like in the admin.py file:

class CarVolumeInline(admin.TabularInline):
    model = CarVolume
    template = "admin/vans/volumesTabularTemplate.html"
    min_num = 0
    max_num = 20
    extra = 1

    def get_queryset(self, request):
        qs = super().get_queryset(request)
        qs.hello = "Hellooo"
        return  qs

class CarAdmin(TranslationAdmin):
    inlines = [CarVolumeInline] # таблица с размерами автомобиля
    list_display = ('full_title', 'seo_set', 'slug')
    ...

The customer asked to add a Multiplier to each dimension, which is unique not only for each dimension, but also for a separate entity - Material Thickness. I created a separate template for TabularInline to display the header and forms for coefficients, but I have absolutely no idea how to save this in the database. Actually, this is the question - how to save, edit and display existing values ​​in such a scheme.
5hvlF.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
FulTupFul, 2019-05-23
@FulTupFul

In order to answer your question, you need what fields your models have and what you display in the admin panel. And so the answer is very simple, override the formset in your inline model

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question