On Nov 18, 12:18 am, Derek <gamesb...@gmail.com> wrote: > It would be great if perhaps one of you could write up a more detailed > description (i.e with code) of this as a blog entry... or maybe a wiki page?
Derek, before I posted the vague description above, I looked at my code for an example that is open source and also simple enough to understand. I'll post some links below, but beware, the code is very complicated and may make no sense to anybody but me. And I don't know how much of that is necessary complexity, and how much is my inability to simplify more. A lot of it is necessary, but I'll explain one potential simplification at the end of this message. The use case is supply and demand and income planning for a local food network. Both producers and customers enter their plans for the future in weekly table columns, with rows for products. Any given producer or customer may not have any plans for some products or some weeks. Then another set of views collects them all in supply vs demand and projected income tables. The planning_table view is at: https://github.com/bhaugen/foodnetwork/blob/master/distribution/views.py#L202 It calls plan_weeks: https://github.com/bhaugen/foodnetwork/blob/master/distribution/view_helpers.py#L210 ...which uses the class PlannedWeek: https://github.com/bhaugen/foodnetwork/blob/master/distribution/view_helpers.py#L202 ...and then it calls create_weekly_plan_forms: https://github.com/bhaugen/foodnetwork/blob/master/distribution/view_helpers.py#L11 A lot of the complexity of the code is because the plan objects in the database is by start and end date, not week. In other words, not only is the table sparse, it is also a different shape from the database objects. The database model is here: https://github.com/bhaugen/foodnetwork/blob/master/distribution/models.py#L681 I hope that all communicated. I would not recommend this as something to emulate, but it does work. Were I to do it over again, I would use week number rather than dates, and may bite the bullet and refactor that way, at the cost of converting existing data. In other words, I think it would help if the data and the table corresponded better, however sparse the data may be. P.S. this project undergoes pretty constant change and is not guaranteed to work at any given time. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.