Reputation: 593
I have admin panel in Django 1.8 with my code in admin.py file:
Here is part of my model:
TYPES_CHOICES = (
('normal', 'normal'),
('archive', 'archive'),
)
class Period(models.Model):
date_start = models.DateTimeField(help_text='date_start')
date_end = models.DateTimeField(help_text='date_end')
type = models.CharField(choices=TYPES_CHOICES, default=TYPES_CHOICES[0][0], max_length=10)
class PeriodAdmin(admin.ModelAdmin):
list_display = ('id', 'date_start', 'date_end', 'description',
'note', 'is_published', 'is_actual', 'type', )
search_fields = ('id', 'note', 'description', 'description_en',)
fields = ['type', ]
My problem is, how to switch type field in to editable field, to switching field value form model. I can not found this is documentation. Please for any hint.
Upvotes: 3
Views: 12824
Reputation: 152
I think you want to editable field on your list
models.py :
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
TYPES_CHOICES = (
('normal', 'normal'),
('archive', 'archive'),
)
class Period(models.Model):
date_start = models.DateTimeField(help_text='date_start')
date_end = models.DateTimeField(help_text='date_end')
period_type = models.CharField(choices=TYPES_CHOICES, default=TYPES_CHOICES[0][0], max_length=10)
admins.py :
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.contrib import admin
from .models import Period
class PeriodAdmin(admin.ModelAdmin):
list_display = ('id', 'date_start', 'date_end', 'period_type',)
list_editable = ('date_start', 'date_end', 'period_type', )
admin.site.register(Period, PeriodAdmin)
Upvotes: 8