DateTimeFluxCapacitor

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
class DateTimeFluxCapacitor(models.DateTimeField):
	def __init__(self,verbose_name = None, name = None, flux_day = 0, flux_hour = 0, flux_minute = 0, flux_second = 0 , **kwargs):
		self.flux_day , self.flux_hour , self.flux_minute , self.flux_second = flux_day , flux_hour , flux_minute , flux_second
		if self.flux_day or self.flux_hour or self.flux_minute or self.flux_second:
			kwargs['blank'] = True
			kwargs['editable'] = False
		super(DateTimeFluxCapacitor,self).__init__(verbose_name,name,False,False)

	def pre_save(self,model_instance,add):
		if self.flux_day or self.flux_hour or self.flux_minute or self.flux_second:
			value = datetime.datetime.now() + datetime.timedelta(days = self.flux_day , hours = self.flux_hour , minutes = self.flux_minute , seconds = self.flux_second )
			setattr(model_instance,self.attname,value)
			return value
		else:
			return super(DateTimeFluxCapacitor,self).pre_save(model_instance,add)
	def get_internal_type(self):
		return "DateTimeField"

More like this

  1. Complete Persian DateTime Widget by serj1975 2 years, 4 months ago
  2. Converting a Flickr Datetime to a Python Datetime by obeattie 7 years, 1 month ago
  3. Converting datetime to Javascript milliseconds in epoch by guychi 6 years, 7 months ago
  4. Parse datetime model field to string by jzelez 3 years, 9 months ago
  5. JSON encode ISO UTC datetime by japerk 5 years ago

Comments

(Forgotten your password?)