1

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') 
2
  • What does your admin.py look like? Commented Jul 18, 2013 at 3:46
  • I updated my question to include admin.py for you Commented Jul 18, 2013 at 3:48

2 Answers 2

4

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)

Sign up to request clarification or add additional context in comments.

3 Comments

There are 14+ tables in the actual models.py- I stripped it down for simplicity. Nevertheless, I tried just doing a straight admin.site.register for each model and converting all of them to Uppercase syntax to keep things pythonic, but this did not work.
I know that if I delete archive from my image class, django is using it as some sort of key identifyer and throws an error when I go to make a new image in the admin web ui, if that's helpful to someone.
Works. I started over with mysql, and renamed to MyImage, but I suspect I needed to wipe the database to get it working. Thank you for the help though- I gave you as many points as I could for your time!
1

I do not see any problem do you have some extra code in admin? Some code that overrides the album field ?

Photo

2 Comments

You're right. My database just exploded. Might take me a while to recover back to this point, thanks for y'all's patience. I'll report back soon.
Fixed. It was either MyImage or resetting the whole database. I suspect the latter.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.