3

I've two simple Django model classes,

models.py

from django.db import models

class ParentModel(models.Model):
    small_text = models.CharField(max_length=20)
    big_text = models.CharField(max_length=500)

    def __str__(self):
        return self.small_text


class ChildModel(models.Model):
    parent = models.ForeignKey(ParentModel)

    def __str__(self):
        return '%s is my parent' % self.parent

admin.py

from django.contrib import admin
import models

admin.site.register(models.ChildModel)
admin.site.register(models.ParentModel)

So the default view is you see the 'small_text' in a select element in the admin section. What I'd love to be able to do is extend that so that there's another TextArea, or something else I can , underneath the select which changes as you choose a different Daddy.

I've looked into a few different ways to do this, but they all seem hella complicated for what with Django, I'd have thought should be an easy task. Any ideas?

4

1 回答 1

1

If you're looking to be able to change ChildModel's properties while viewing the ParentModel in the admin, you should look into using an inline in the admin

If you're looking to have additional fields appear when viewing the index page in the admin for a model, then you'll want to add additional properties to the list_display property on the model's admin class.

于 2013-08-13T01:53:32.883 回答