Answer the question
In order to leave comments, you need to log in
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
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)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question