gpt4 book ai didi

django - grappelli隐藏内联可排序(Django Admin)中的可排序字段

转载 作者:行者123 更新时间:2023-12-03 13:52:28 26 4
gpt4 key购买 nike

从grappelli定制文档中,它建议:

    The sortable-field will not automatically be hidden
(use a Hidden Input Widget if needed).

但是,我已经搜索了很长时间,对什么是“隐藏的输入小部件”以及如何将其实现为Django模型一无所知。这是我的代码:
     # models.py
class video(models.Model):
category = models.ForeignKey(subCategory)
index = PositionField('index')
video_title = models.CharField(max_length=255, blank=True, null=True)
video_desc = models.TextField(blank=True, null=True)
main_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
small_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
mid_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
large_img = S3EnabledImageField(upload_to='video_img', blank=True, null=True)
last_updated = models.DateField(auto_now=True)
date_added = models.DateField()
date_modified = models.DateField()
date_published = models.DateField(blank=True, null=True)
date_closed = models.DateField(blank=True, null=True)
status = models.CharField(max_length=7,choices=STATUS_CHOICE)

class Meta:
ordering = ('index',)
verbose_name = 'Video'
verbose_name_plural = 'Video'

def __unicode__(self):
return self.video_title

class video_file(models.Model):
video = models.ForeignKey(video)
index = models.PositiveIntegerField()
file_title = models.CharField(max_length=255, blank=True, null=True)
#main_file = models.ImageField(upload_to='phoneso/video_file', blank=True, null=True)
main_file = S3EnabledFileField(upload_to='video_file')
resolution = models.CharField(max_length=50, blank=True, null=True)
file_format = models.CharField(max_length=50, blank=True, null=True)
date_added = models.DateField(auto_now_add=True)
date_published = models.DateField(auto_now_add=True)
status = models.CharField(max_length=7,choices=STATUS_CHOICE)

class Meta:
ordering = ('index',)
verbose_name = 'Video File'
verbose_name_plural = 'Video File'

def __unicode__(self):
return self.video.video_title

# admin.py

class video_fileInline(admin.TabularInline):
fields = ('main_file' , 'resolution' , 'file_format' , 'status', 'index',)
sortable_field_name = 'index'
model = video_file
extra = 1

class videoAdmin(admin.ModelAdmin):
list_display = ('index' , 'video_title', 'category' , 'date_added' , 'date_published' , 'status')
search_fields = ['video_title', 'desc']
readonly_fields = ('date_added','date_modified')
list_filter = ['category']
inlines = [video_fileInline]

class video_fileAdmin(admin.ModelAdmin):
list_display = ('index' , '__unicode__' , 'file_title', 'resolution' , 'file_format' , 'main_file' , 'date_added' , 'date_published' , 'status')
search_fields = ['video_title', 'desc']

我应该在哪里实现建议的“隐藏输入小部件”?

谢谢你。

最佳答案

您可以为模型编写一个表单,并在video_fileInline中使用它:

表格

class VideoFileForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(VideoFileForm, self).__init__(*args, **kwargs)
# key should be your sortable-field - in your exaple it's *index*
self.fields['index'].widget = forms.HiddenInput()

class Meta:
model = video_file

管理员
class video_fileInline(admin.TabularInline):
fields = ('main_file' , 'resolution' , 'file_format' , 'status', 'index',)
form = VideoFileForm
sortable_field_name = 'index'
model = video_file
extra = 1

关于django - grappelli隐藏内联可排序(Django Admin)中的可排序字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6958708/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com