Guest User

Untitled

a guest
Nov 19th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. class Group(models.Model):
  2. name = models.CharField(max_length=30)
  3.  
  4. class Person(models.Model):
  5. group = models.ForeignKey(Group)
  6. first_name = models.CharField(max_length=30)
  7. last_name = models.CharField(max_length=30)
  8.  
  9. class Phone(models.Model):
  10. persons = models.ManyToManyField(Person)
  11. number = models.CharField(max_length=30)
  12.  
  13. class PersonInline(admin.StackedInline):
  14. model = Person
  15.  
  16. class PhoneInline(admin.StackedInline):
  17. model = Phone # also tried: Phone.persons.through
  18.  
  19. @admin.register(Group)
  20. class GroupAdmin(admin.ModelAdmin):
  21. inlines = [PersonInline, PhoneInline]
Add Comment
Please, Sign In to add comment