Reputation: 1856
For some reason, the classes archive
and album
show all of their fields in the django admin panel, but image
isn't showing an album
field when I go to add an image to the image panel. If I open a shell, it shows that album
is a subset of image
, it just isn't showing up in the image
's admin interface (but it does through the CLI). Why?
class archive(models.Model):
name = models.CharField(max_length = 30)
archivedata = models.TextField(blank=True, help_text="Documentation for album/image.archivedata methodology is put here")
def __unicode__(self):
return self.name
class tag(models.Model):
archive = models.ForeignKey(archive)
tag = models.CharField(max_length=60)
def __unicode__(self):
return self.tag
class album(models.Model):
archive = models.ForeignKey(archive)
title = models.CharField(max_length=60)
tags = models.ManyToManyField(tag, blank=True, help_text="Searchable Keywords")
archivedata = models.TextField(blank=True, null=True, help_text="Data specific to particular archiving methods or processes can be stored here")
def __unicode__(self):
return self.title
class image(models.Model):
album = models.ForeignKey(album)
archive = models.ForeignKey(archive)
imagefile = models.ImageField(upload_to='ns/') #image.width/height
title = models.CharField(max_length=60, blank=True, help_text="Descriptive image title")
tags = models.ManyToManyField(tag, blank=True, help_text="Searchable Keywords")
Update: Including my admin.py per request:
from django.db.models import get_models, get_app
from django.contrib import admin
from django.contrib.admin.sites import AlreadyRegistered
def autoregister(*app_list):
for app_name in app_list:
app_models = get_app(app_name)
for model in get_models(app_models):
try:
admin.site.register(model)
except AlreadyRegistered:
pass
autoregister('appname')
Upvotes: 1
Views: 2266
Reputation: 10811
I do not see any problem do you have some extra code in admin? Some code that overrides the album field
?
Upvotes: 1
Reputation: 7032
Your admin.py
file should typically look like this.
from django.contrib import admin
admin.site.register(archive)
admin.site.register(album)
admin.site.register(image)
Based on your admin.py I would do this.
autoregister('archive', 'album', 'image')
That said a few pointers - Your admin.py is a bit overly complicated and not needed when 3 lines will suffice. Additionally you should be naming your models in uppercase (Archive, Album, Image)
Upvotes: 4