def test_iso8601_conversion(self): import datetime field = micromodels.DateField() field.populate("2010-12-28") result = field.to_python() expected = datetime.date(2010,12,28) self.assertEqual(expected, result) field = micromodels.DateField() field.populate("20101228") result = field.to_python() expected = datetime.date(2010,12,28) self.assertEqual(expected, result)
def test_model_late_assignment(self): instance = self.Person.from_dict(dict(name='Eric')) self.assertEqual(instance.to_dict(), dict(name='Eric')) instance.age = 18 self.assertEqual(instance.to_dict(), self.data) instance.name = 'John' self.assertEqual(instance.to_dict(), dict(name='John', age=18)) instance.age = '19' self.assertEqual(instance.to_dict(), dict(name='John', age=19)) format = '%m-%d-%Y' today = date.today() today_str = today.strftime(format) instance.add_field('birthday', today_str, micromodels.DateField(format)) self.assertEqual(instance.to_dict()['birthday'], today) instance.birthday = today self.assertEqual(instance.to_dict()['birthday'], today)
class Event(micromodels.Model): time = micromodels.DateField(format="%Y-%m-%d")
class Person(micromodels.Model): aliases = micromodels.FieldCollectionField(micromodels.CharField()) events = micromodels.FieldCollectionField(micromodels.DateField('%Y-%m-%d', serial_format='%m-%d-%Y'), source='schedule')
def setUp(self): self.format = "%Y-%m-%d" self.datestring = "2010-12-28" self.field = micromodels.DateField(format=self.format)
class SimpleModel(micromodels.Model): name = micromodels.CharField() field_with_source = micromodels.CharField(source='foo') field_with_default = micromodels.DateField(default=date.today)