Saturday, December 29, 2012

Re: Design by composition and persistance


in your case:

class Event(models.Model):
  name = models.CharField(.....)
  description = models.CharField(....)
  tw_start = models.DateTimeField(....)
  tw_finish= models.DateTimeField(....)
  timewindow = TimeWindowField(tw_start, tw_finish)

and getDuration() is a method of the TimeWindowField, so you can say
event.timewindow.getDuration()


--
Javier

I was thinking of doing something similar to Javier's suggestion of storing the underlying content 'flat' on the same table, and then creating an abstraction layer. I've tried out the sample code, and  calling event.timeWindow returns a TimeWindowField object (which you can call 'getDuration' on), but setting the timewindow attribute to some other value doesn't propagate the values onto the tw_start & tw_finish fields, and using the query api doesn't work either (not that I was expecting either to work :)). You could work around this by using getters/setters (via properties), but that feels like a long road to go down to come up with a generic solution (DRY) & make sure that it works in the general case. Also, once you've implemented setting/getting, then what about other parts of Django functionality, notably querying and model form generation, that are coupled to the model.. how would support for those be added?  

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/-ZFFEqWhVw8J.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment