Django get model datefield value

162 Views Asked by At
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>>

How do I get the value of the date field specifically the year?

1

There are 1 best solutions below

0
On BEST ANSWER

I solved it this way

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