Django - master / detail

(Leandro Costa) #1

Hi

That would be a good idea for an article :slight_smile:
Django admin application for master / detail page

class Item(models.Model):
    title = models.CharField(max_length=200)
    pub_date = models.DateTimeField()

class ItemDetail(models.Model):
    item = models.ForeignKey(Item)
    name = models.CharField(max_length=200)
    value = models.CharField(max_length=200)
    display_order = models.IntegerField()
title:    <       >
pub_date: <       >
details:
+-----------------+----------------------+-------------------------+
|       name      |        value         |      diplay order       |
+-----------------+----------------------+-------------------------+
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
+-----------------+----------------------+-------------------------+

I can do it in the interface in htttp://127.0.0.1:8000/admin/, using the following code::

class ItemDetailInline(admin.TabularInline):
    model = ItemDetail

class ItemAdmin(admin.ModelAdmin):
    inlines = [
        ItemDetailInline,

.

I would like to reproduce what I saw in admin,
Making a CRUD using CrispyForms, Bootstrap 4.
Can anybody help me ?

What would be the best solution?

Also do some calculated fields, what would be the best form in django?

quote:

(Lúcio Henrique) #2

I also recommend django-tables2. It´s a good solution to creating html tables dynamically. Like django-crispy but for tables.