Je veux me créer admin comme ceci: http://lightbird.net/dbe/_static/p1.pngInterface Admin App Gallery
Ce que j'ai droit est maintenant:
def get_upload_file_name(instance, filename):
new_file_path_and_name = os.path.join(MEDIA_ROOT,'img/albums')
return new_file_path_and_name
class Album(models.Model):
title = models.CharField(max_length = 60)
def __unicode__(self):
return self.title
class Tag(models.Model):
tag = models.CharField(max_length = 50)
def __unicode__(self):
return self.tag
class Image(models.Model):
title = models.CharField(max_length = 60, blank = True, null = True)
image = models.FileField(upload_to = get_upload_file_name)
tags = models.ManyToManyField(Tag, blank = True)
albums = models.ForeignKey(Album)
width = models.IntegerField(blank = True, null = True)
height = models.IntegerField(blank = True, null = True)
created = models.DateTimeField(auto_now_add=True)
def tags_(self):
lst = [x[1] for x in self.tags.values_list()]
return str(join(lst, ", "))
def albums_(self):
lst = [x[1] for x in self.albums.values_list()]
return str(join(lst, ", "))
def __unicode__(self):
return self.image.name
class AlbumAdmin(admin.ModelAdmin):
search_fields = ["title"]
list_display = ["title"]
class TagAdmin(admin.ModelAdmin):
list_display = ["tag"]
class ImageAdmin(admin.ModelAdmin):
search_fields = ["title"]
list_display = ["__unicode__", "title", "tags_", "albums_", "created"]
list_filter = ["tags", "albums"]
admin.site.register(Album, AlbumAdmin)
admin.site.register(Tag, TagAdmin)
admin.site.register(Image, ImageAdmin)
Je ne sais pas ce qu'est une entrée acceptable pour la list_display de ImageAdmin. Je suis le tutoriel lightbird (http://lightbird.net/dbe/photo.html) mais comme il est démodé, je fais certains de mes propres choix en cours de route. Je ne suis pas sûr de savoir comment modifier ma méthode tags_ et albums_ pour obtenir la mise en page d'administration.
Je reçois l'erreur:
File "/Users/bradfordli/Development/DjangoEnvironment/django_1_6_4/bin/PersonalWebsite/gallery/models.py" in tags_
45. return str(join(lst, ", "))
Exception Type: NameError at /admin/gallery/image/
Exception Value: global name 'join' is not defined
Je ne sais pas comment résoudre ce problème que je ne suis pas sûr de list_display's
entrée appropriée
Merci! MAIS, je ne reçois pas cette erreur L'objet 'Album' n'a pas d'attribut 'values_list'' – Liondancer
@Liondancer Je suis sûr que vous ne le faites pas correctement. Jetez un coup d'oeil: http://stackoverflow.com/questions/4013585/django-include-data-from-foreignkey-in-admin-list-display-function et http://stackoverflow.com/questions/163823/can- list-display-in-a-django-modeladmin-affichage-attributs-de-foreignkey-field. J'espère que cela aide. – alecxe