Note that there are some explanatory texts on larger screens.

plurals
  1. POBetter Django UI for one to many relationship
    primarykey
    data
    text
    <p><strong>First</strong><br> I love Django, I like it because with just few lines of describing Model I get full CURD web app.<br> Now I am having app that need one-to-many relationship and it is not working as I am expecting.</p> <p>I question is based on: <a href="https://stackoverflow.com/questions/6928692/how-to-express-a-one-to-many-relationship-in-django">How to express a One-To-Many relationship in Django</a></p> <p>So this is my code:</p> <p><strong>models.py</strong></p> <pre><code>from django.db import models class Dude(models.Model): name = models.CharField(blank=False, null=False, max_length=100, unique=True) def __unicode__(self): return u"%s" % self.name class PhoneNumber(models.Model): dude = models.ForeignKey(Dude) number = models.CharField(blank=False, null=False, max_length=100, unique=True) </code></pre> <p><strong>admin.py</strong></p> <pre><code>from django.contrib import admin from TestingDjango.apps.one_to_many.models import Dude, PhoneNumber class DudeAdmin(admin.ModelAdmin): pass list_display = ('name',) class PhoneNumberAdmin(admin.ModelAdmin): pass list_display = ('dude', 'number') admin.site.register(Dude, DudeAdmin) admin.site.register(PhoneNumber, PhoneNumberAdmin) </code></pre> <p>When I operate admin web UI I need to add Dude and after that I need to go to PhoneNumber, and for each number for same dude I need to add new row (and select same dude again and again).</p> <p>What I was expecting was following: - when I am addend new dude, in same page, I will have "+" button where I could add multiple numbers for one dude. And after that click save. When I look at dude I will see all numbers for that dude, now I need to go to PhoneNumber to see all numbers per dude.</p> <p>How to do it ?<br> Is it even possible with just editing admin.py or I need to write my own view for that ?<br> If I need to write my own view for that, please give some guidelines how to do it ? </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.
 

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