R
R
Ruslan Bergutov2015-04-28 12:47:34
Django
Ruslan Bergutov, 2015-04-28 12:47:34

How to change django code?

I am learning to write in django, I am analyzing an example of a working gallery, I wonder how you can change / add code for the following effect:
Here is the code:
myapp/models.py

#! coding: utf-8
from django.db import models
# Альбом с фотографиями
class Album(models.Model):
    title = models.CharField("Название альбома", max_length=100)
    slug = models.SlugField("Ссылка для альбома", max_length=100, unique=True)
    img = models.ImageField("Изображение альбома", upload_to='images',
                            help_text='Размер изображения 200px на 200px')

    class Meta:
        ordering = ['title']
        verbose_name = 'Альбом'
        verbose_name_plural = 'Альбомы'

    def __unicode__(self):
        return self.title



class Photo(models.Model):
    title = models.CharField("Название фотографии", max_length=100)
    album = models.ForeignKey(Album, verbose_name='Альбом')
    img = models.ImageField("Фото", upload_to='images',
                            help_text='Желательно, чтоб фото было не большого размера')

    class Meta:
        ordering = ['title']
        verbose_name = 'Фото'
        verbose_name_plural = "Фотографии"

    def __unicode__(self):
        return self.title

myapp/admin.py
from django.contrib import admin
from photos.models import Album, Photo
#
#Для альбома
class AlbumAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {'fields': ['title', 'slug', 'img']})
    ]
    list_display = ['title', 'slug']
    prepopulated_fields = {'slug': ['title']}
    ordering = ['title']
#
#Для фотографии
class PhotoAdmin(admin.ModelAdmin):
    fieldsets = [
        (None, {"fields": ['title', 'album', 'img']})
    ]
    list_display = ['title', 'album']
    ordering = ['title']


admin.site.register(Album, AlbumAdmin)
admin.site.register(Photo, PhotoAdmin)

You can create an album in which images will be uploaded, but when uploading an image, the names of the albums are not displayed, but simply called the standard Album Object
. I will also be grateful for the good instruction on displaying image thumbnails in the

e6890b749cfa4fd58de55b3fed3f7c01.png
pip list admin panel:
  • django-appconf (1.0.1)
  • django-disqus (0.5)
  • django-imagekit (3.2.6)
  • mock (1.0.1)
  • pilkit (1.1.12)
  • Pillow (2.8.1)
  • pip (6.1.1)
  • setuptools (15.0)
  • six (1.9.0)

Python 3.4
It's just that in the future you can see this incoherent garbage:
2cdad8d246be4866ae1f800502431151.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sim3x, 2015-04-28
@Scirocco

def __unicode__(self):  # python 2
def __str__(self):  # python 3

stackoverflow.com/questions/1385094/django-admin-a...
https://google.com/search?q=django+admin+show+images

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question