models.py
from django.db import models
class new_posts(models.Model):
title = models.CharField(max_length = 50,verbose_name = 'Заголовок')
content = models.TextField(verbose_name = 'Описание новости')
published = models.DateTimeField(auto_now_add = True,db_index = True,verbose_name = 'Дата публикации')
add_mus = models.FileField(upload_to = 'arch/%Y/%m/%d/',verbose_name = 'Файл', null = True,blank = True)
genre = models.ForeignKey('Rub',on_delete = models.PROTECT)
class Meta(object):
ordering = ['-published']
class Rub(models.Model):
name = models.CharField(max_length = 20,db_index = True,verbose_name = 'Жанр')
def __str__(self):
return self.nameКод
admin.py
from django.contrib import admin
from .models import *
admin.site.register(new_posts)
class new_postsAdmin(admin.ModelAdmin):
list_display = ('title','content','published','add_mus',)
list_display_links = ('title','content','add_mus',)
search_fields = ('title','content','add_mus',)