Django sets DateField from DateTimeField

Simply put, this is my question:

class A(models.Model):
  x = DateTimeField(...)

class B(models.Model):
  x = DateField(...)

Given an instance of A and B, how easy is it to set bx to ax? Just setting bx to ax causes bx to not be None.

Thanks in advance.

+3
source share
1 answer

Use datetime.datetime.date()to get the component dateas follows:

a = A()
b = B()

# Stuff

b.x = a.x.date()

See http://docs.python.org/library/datetime.html#datetime-objects for more details .

+3
source

All Articles