2013-03-18 230 views
0

嗨,大家好我有這個模型Django模型和管理面板

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

是否有可能以顯示管理面板的ctime場沒有浮動,但隨着時間字段?

+1

爲什麼不申報當您在那裏存儲時間戳時,模型字段爲DateField? https://docs.djangoproject.com/en/dev/ref/models/fields/#datefield – 2013-03-18 16:54:06

+0

因爲如果我將聲明此字段DateField,我將無法在此存儲浮動時間戳。 – vovaminiof 2013-03-18 16:55:22

回答

0

檢查Django documentation。您可以覆蓋默認小部件模型領域 -

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}, 
    } 

或者,一個單一的模式,如this answer描述 -

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

class StopAdmin(admin.ModelAdmin): 
    form = StopAdminForm 

檢查其他的答案在這個問題too.a