0

Hi guys I have this model

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

Is it possible to display ctime field in admin panel not as float but as time field?

Dan Hanly
  • 7,829
  • 13
  • 73
  • 134
vovaminiof
  • 511
  • 1
  • 4
  • 13
  • 1
    Why not declare the model field as DateField, when you are storing a timestamp there? https://docs.djangoproject.com/en/dev/ref/models/fields/#datefield – Sami N Mar 18 '13 at 16:54
  • Because if i will declare this field DateField i will not be able store float timestamp here. – vovaminiof Mar 18 '13 at 16:55

1 Answers1

0

Check Django documentation. You can override default widgets for model fields -

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

Or, for a single model, as described in this answer -

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

class StopAdmin(admin.ModelAdmin):
  form = StopAdminForm

Check other answers in that question too.a

Community
  • 1
  • 1
Bibhas Debnath
  • 14,559
  • 17
  • 68
  • 96