0

大家好,我有这个模型

class Class1(models.Model):
    ....
    ctime = models.FloatField()  # I am storing date in timestamp here
    ....

是否可以在管理面板中将 ctime 字段显示为浮点数而不是时间字段?

4

1 回答 1

0

检查Django 文档。您可以覆盖模型字段的默认小部件 -

from django.db import models
from django.contrib import admin

# Import our custom widget and our model from where they're defined
from myapp.widgets import RichTextEditorWidget
from myapp.models import MyModel

class MyModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.TextField: {'widget': RichTextEditorWidget},
    }

或者,对于单个模型,如本答案中所述-

class StopAdminForm(forms.ModelForm):
  class Meta:
    model = Stop
    widgets = {
      'approve_ts': ApproveStopWidget(),
    }

class StopAdmin(admin.ModelAdmin):
  form = StopAdminForm

也检查该问题中的其他答案。a

于 2013-03-18T17:03:11.223 回答