Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can use <code>InlineAdmin</code></p> <p>In your admin.py</p> <pre><code>class PhoneNumberInline(admin.TabularInline): model = PhoneNumber # related model extra = 1 # number of new record fields class DudeAdmin(admin.ModelAdmin): inlines = [PhoneNumberInline, ] admin.site.register(Dude, DudeAdmin) </code></pre> <p>This will display all related <code>PhoneNumber</code> records under the <code>Dude</code> record adn you can add new or update or delete existing records. That is all in a single page as you want. <a href="https://docs.djangoproject.com/en/1.3/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin" rel="nofollow">Documentation is here</a> . In this approach, you do not need to add <code>PhoneNumber</code> directly to your admin.</p> <p><strong>Update:</strong> You can see related phone numbers or how many phone numbers are recorded to there. First you must define a method that will return phone numbers (or number of phones) to your <code>Model</code></p> <pre><code>class Dude(models.Model): name = models.CharField(blank=False, null=False, max_length=100, unique=True) def list_phones(self): phone_numbers = self.phonenumber_set.values_list('number', flat=True) # use reverse relation to get a list ofall recorded numbers phone_count = self.phonenumber_set.count() return "This user have %s numbers recorded: %s" % (phone_count, ', '.join(phone_numbers)) def __unicode__(self): return u"%s" % self.name </code></pre> <p>And in your <code>ModelAdmin</code></p> <pre><code>class DudeAdmin(admin.ModelAdmin): list_display = ('name', 'list_phones') </code></pre> <p>You can use methods defined under your <code>Model</code> just as model fields. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload