Updating a date field

32 views
Skip to first unread message

Clive Bruton

unread,
Jun 13, 2020, 10:25:04 PM6/13/20
to django...@googlegroups.com
I am trying to update an existing date field, however when I do that
I get the following exception:

Exception Type: TypeError
Exception Value: expected string or bytes-like object

The query looks like this:

queryset = Item.edit.filter(**kwargs).update
(expires=set_expires,is_active=True)

and set_expires looks like this:

def set_expires():
return datetime.now(timezone.utc) + timedelta(days=30)

I am using "set_expires" in the model for "Item", to set the initial
value, without issue. Do I have to convert to a string when doing an
update?

Thanks


-- Clive

Clive Bruton

unread,
Jun 14, 2020, 11:00:58 PM6/14/20
to django...@googlegroups.com
Apparently the magic is:

queryset = Item.edit.filter(**kwargs).update(expires=set_expires
(),is_active=True)


-- Clive
> --
> You received this message because you are subscribed to the Google
> Groups "Django users" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to django-users...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/
> d/msgid/django-users/8B6B6771-0E9C-4E4A-A696-18CF9B7ED355%
> 40indx.co.uk.
>

Reply all
Reply to author
Forward
0 new messages