[SOLVED] strptime() argument 1 must be str, not DeferredAttribute


This Content is from Stack Overflow. Question asked by user19686784

I am heaving trouble here, am making a travel and visa website, am trying to make sure we know each appointment 10 days in advance.
So I made a model property that would help me compare dates, but am having trouble error after error
here is the model field

class customer(models.Model):
first_name = models.CharField(max_length=255, default='')
last_name = models.CharField(max_length=255, default='')
biometry_date = models.DateField(blank=True, default='', null=True)

def is_due(self):
    datetime_object = datetime.strptime(Profile.biometry_date, '%Y-%m-%d')
    t2 = datetime.now().date()
    t3 = timedelta(days=30)
    return  datetime_object - t2<= t3

and in the Html template

{% if profile.is_due %}
<td class="text-right">
<span class="badge badge-danger">{{ profile.biometry_date }}</span>
{% else %}
<td>{{ customer.biometry_date }}</td>
{% endif %}

Please help me


Firstfully, as Willem pointed – you don’t need to use strptime from field, it’s already datetime.datetime object. And you should use self when you want to use the object’s field values. So:

def is_due(self):
    datetime_object = self.biometry_date

Secondly, I think you try to use interchangeably profile and customer. Decide which you are going to use or at least share the context.

This Question was asked in StackOverflow by St JC and Answered by NixonSparrow It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?