Django 获取模型日期字段值
Django get model datefield value
class Bla(Case):
def __init__(self, model, field, condition=None, then=None, **lookups):
la = model._meta.get_field(field).__str__
returns
<bound method Field.__str__ of <django.db.models.fields.DateField: date>>
如何获取日期字段的具体年份值?
我是这样解决的
class Bla(Case):
def __init__(self, model, field, condition=None, then=None, **lookups):
la = model.objects.first()
field_object = model._meta.get_field(field)
field_value = field_object.value_from_object(la)
year = field_value.year
class Bla(Case):
def __init__(self, model, field, condition=None, then=None, **lookups):
la = model._meta.get_field(field).__str__
returns
<bound method Field.__str__ of <django.db.models.fields.DateField: date>>
如何获取日期字段的具体年份值?
我是这样解决的
class Bla(Case):
def __init__(self, model, field, condition=None, then=None, **lookups):
la = model.objects.first()
field_object = model._meta.get_field(field)
field_value = field_object.value_from_object(la)
year = field_value.year