Django admin app for home / detail page

Consider this simplified model in Django:

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()

Is there a way to use admin to edit an element with its details on the same page with a form that looks something like this:

title:    <       >
pub_date: <       >
details:
+-----------------+----------------------+-------------------------+
|       name      |        value         |      diplay order       |
+-----------------+----------------------+-------------------------+
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
|<               >|<                    >|<                       >|
+-----------------+----------------------+-------------------------+

Where there < >will be a placeholder for input types for data entry.

So my question is: can I use admin to edit the relationship foreign keyfrom the perspective of the parent? If there is no way to edit data with a Django administrator this way, would it be nice to try extending / configuring admin for this? Any directions on how to do this?

Thank!

+5
source share
1 answer

, django , - , ( ).

, ModelAdmin:
http://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin

class ItemDetailInline(admin.TabularInline):
    model = ItemDetail

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

All Articles