Hi, Seems you need here admin inlines, these allow you to insert/edit related objects inline when editing the main object. For example, when editing a Site, you will be able to also edit Images and Locations, though it only supports 1 level, so with default configuration you may probably not be able to also edit LocImages. Start reading here: http://localhost/Python/django-docs-1.10-en/ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.inlines
To support more levels, you can use django-nested-admin package: https://pypi.python.org/pypi/django-nested-admin On Monday, April 10, 2017 at 7:48:37 PM UTC-4, Liam H wrote: > > Hi, > > I'm new to Django, programming, web apps, the whole lot. I've been working > on an app for a while now, but I'm having trouble figuring out how to > organise my models in an effective way. Im using Django 1.10 and Python 2.7. > > Here's a rough example of the structure I'm trying: > > class Site(models.Model): > #... > def __unicode__(self): > return self.name > > class Image(models.Model): > #... > site = models.ForeignKey(Site, ...) > def __unicode__(self): > return self.name > > class Location(models.Model): > #... > site = models.ForeignKey(Site, ...) > def __unicode__(self): > return self.name > > class LocImage(models.Model): > #... > location = models.ForeignKey(Location, ...) > def __unicode__(self): > return self.name > > > > The idea is to have a site (like a castle or other area the user might > want to visit), and then each site will have various Images like aerial > photographs associated with it. Each site will also have various locations > around it with multiple images associated with that location. > > So it works something like this: > > Site > > Images > > Location > > LocImages > > > > I've tried doing it this way, but I don't know how to get the admin page > to show this, for one. I read a post that said that Django's admin page > can't have nested related items like this, but I'm not sure if that's > actually true. I was able to run migrations on this code when I removed the > references to it in the admin page, but I don't know how to access the > LocImages model in the API, like I can with the Location and Images models > using something like > "Site.objects.get(pk=2).location_set.get(id=2).locimage_set.all()". > > So, is this how I should be structuring the models? And if it works in the > database is there any way to get this to show on a single page in the > Django admin? > > The reason I decided to structure it this way is so each location can have > multiple attributes that are all fields of the same model, making it easier > to link them together in the templates. > > Any help would be appreciated, thanks. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1a6c9dff-e7e8-41a2-96b5-7f6d08c88f77%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.