@@ -98,6 +98,15 @@ Imagine you have the models ``Location`` and ``LocationReportingPeriod``:
98
98
)
99
99
100
100
101
+ def _get_reporting_period_timzone (obj ):
102
+ """ Called as `obj` being the LocationReportingPeriodInstance.
103
+
104
+ Note:
105
+ populate_from=lambda: instance: instance.location.timezone is not valid.
106
+
107
+ """
108
+ return obj.location.timezone
109
+
101
110
class LocationReportingPeriod (models .Model )
102
111
location = models .ForeignKey (
103
112
verbose_name = _ (' location' ),
@@ -108,15 +117,15 @@ Imagine you have the models ``Location`` and ``LocationReportingPeriod``:
108
117
verbose_name = _ (' start' ),
109
118
# populate_from can also be a string value, provided that the string value
110
119
# is a field on the same model
111
- populate_from = lambda instance : instance . location . timezone ,
120
+ populate_from = _get_reporting_period_timzone ,
112
121
# Time override must be a datetime.time instance
113
- time_override = datetime .min .time ,
122
+ time_override = datetime .min .time () ,
114
123
)
115
124
end = LinkedTZDateTimeField (
116
125
verbose_name = _ (' end' ),
117
- populate_from = lambda instance : instance . location . timezone ,
126
+ populate_from = _get_reporting_period_timzone ,
118
127
# Time override must be a datetime.time instance
119
- time_override = datetime .max .time ,
128
+ time_override = datetime .max .time () ,
120
129
)
121
130
122
131
created = LinkedTZDateTimeField (
@@ -244,10 +253,6 @@ Contributors
244
253
Changelog
245
254
---------
246
255
256
+ - 0.3 Code cleanup.
247
257
- 0.2 Multiple bug fixes based on testing.
248
258
- 0.1 Initial release.
249
-
250
- License
251
- =======
252
-
253
- The MIT License.
0 commit comments