Answer the question
In order to leave comments, you need to log in
What is the cause of error in django admin?
For the Post model, the default manager is overridden
#models.py
class ObjectsOnManager(models.Manager):
def get_queryset(self):
return super(ObjectsOnManager, self).get_queryset().filter(status='on')
class OnOffStatusModel(models.Model):
ON = 'on'
OFF = 'off'
STATUS_CHOICES = (
(ON, 'Показывать'),
(OFF, 'Не показывать'),
)
status = models.CharField("Статус", max_length=15, choices=STATUS_CHOICES, default=ON)
objects_on = ObjectsOnManager()
objects = models.Manager()
class Meta:
abstract = True
class Post(OnOffStatusModel):
# определяем поля
......
#admin.py
class PostAdmin(admin.ModelAdmin):
form = PostImageControlForm
fields = ('count', 'status', 'image', 'title', 'descript', 'body', 'main_post', )
list_display = ('title', 'main_post', 'count',)
list_editable = ('main_post', 'status')
list_filter = ('category', 'main_post', 'status')
def get_queryset(self, request):
return Post.objects.all()
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