Re: Absolute beginner question -- recipes

2016-03-07 Thread James Schneider
On Mon, Feb 29, 2016 at 4:51 AM, Simon Gunacker wrote: > @Mike: the attempts (at least the ones I have seen) to store hierarchical > data in relations [1] don't seem very intuitive to me. At least when it > comes to query the data. Anyway: I would appreciate to be

Re: Absolute beginner question -- recipes

2016-03-06 Thread Mike Dewhirst
On 7/03/2016 2:17 AM, Mike Dewhirst wrote: On Thursday, March 3, 2016 at 3:22:04 AM UTC+11, Simon Gunacker wrote: Inspired by Mike Dewhirsts suggestion on building hierachical structures, Not sure we are on the same page regarding "hierarchical". In the early days hierarchical

Re: Absolute beginner question -- recipes

2016-03-06 Thread Mike Dewhirst
On Thursday, March 3, 2016 at 3:22:04 AM UTC+11, Simon Gunacker wrote: > > Inspired by Mike Dewhirsts suggestion on building hierachical structures, > Not sure we are on the same page regarding "hierarchical". In the early days hierarchical databases only had 1:n relationships IOW foreign keys

Re: Absolute beginner question -- recipes

2016-03-02 Thread Simon Gunacker
Inspired by Mike Dewhirsts suggestion on building hierachical structures, I've made up another model: class Part(models.Model): parts = models.ForeignKey('Part', null=True, blank=True, default=None, related_name='pieces') name = models.CharField(max_length=200) Then I made my view:

Re: Absolute beginner question -- recipes

2016-03-02 Thread Simon Gunacker
Thank you James. Taking your suggestion, I solved it! -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this

Re: Absolute beginner question -- recipes

2016-02-29 Thread James Schneider
On Mon, Feb 29, 2016 at 5:57 AM, Simon Gunacker wrote: > Thank you Florian. After James pointed out that I can access my steps (and > the ingredients in some way) by just passing the recipe object to the > templates context, I thought of reducing the view to a

Re: Absolute beginner question -- recipes

2016-02-29 Thread Simon Gunacker
Thank you Florian. After James pointed out that I can access my steps (and the ingredients in some way) by just passing the recipe object to the templates context, I thought of reducing the view to a DetailView again. But I have to somehow access the ingredients from my template for now ... --

Re: Absolute beginner question -- recipes

2016-02-29 Thread Florian Schweikert
On 28/02/16 20:14, Simon Gunacker wrote: > | > def detail(request, pk): > recipe = Recipe.objects.get(id=pk) > recipe['steps'] = Steps.objects.filter(recipe_id=pk) > template = loader.get_template('recipe/recipe_detail.html') > context = { > 'recipe': recipe, > } >

Re: Absolute beginner question -- recipes

2016-02-29 Thread Simon Gunacker
@Mike: the attempts (at least the ones I have seen) to store hierarchical data in relations [1] don't seem very intuitive to me. At least when it comes to query the data. Anyway: I would appreciate to be convinced by something else. However, I am afraid to kick off a completely different (yet

Re: Absolute beginner question -- recipes

2016-02-29 Thread Mike Dewhirst
On 29/02/2016 8:54 PM, Simon Gunacker wrote: Well, as far as I know hierarchical relationships are hard to model in relational databases; Definitely incorrect. Hierarchical is merely a subset of relational. Relational can handle hierarchical 1:n:m very easily plus n:1, n:m as well.

Re: Absolute beginner question -- recipes

2016-02-29 Thread Simon Gunacker
Ok ... but how can I access the additional information stored in StepIngredient then? And - to ask more general - is there a way to find all the "nested objects" attached to my current objects? Something to enter in the shell to see __all__ attributes; not just _meta.fields? -- You received

Re: Absolute beginner question -- recipes

2016-02-29 Thread James Schneider
> Thank you James for pointing me at how to do my queries with django; I can finally list my steps using: > > {% for step in recipe.steps.all %} > > within my template. However, given the model above I am still not sure how to access a single steps ingredients ... any ideas or suggestions on my

Re: Absolute beginner question -- recipes

2016-02-29 Thread Simon Gunacker
Hey everybody, thank you very much for your answers. I think I have already learned a lot from you! Well - there is quite a difference between stepping through a tutorial and trying to do something on my own. Regarding Mikes question whether a step of a recipe should be a sub-recipe. Well, as

Re: Absolute beginner question -- recipes

2016-02-29 Thread James Schneider
On Sun, Feb 28, 2016 at 11:45 PM, Rahul Gandhi wrote: > I might be wrong here, but this is what I understand: > > Let's say you have something like this: > > > class Recipe(models.Model): > name = models.CharField(max_length=255) > description =

Re: Absolute beginner question -- recipes

2016-02-28 Thread Rahul Gandhi
I might be wrong here, but this is what I understand: Let's say you have something like this: class Recipe(models.Model): name = models.CharField(max_length=255) description = models.TextField() class Step(models.Model): step_number = models.IntegerField() description =

Re: Absolute beginner question -- recipes

2016-02-28 Thread Mike Dewhirst
On 29/02/2016 2:09 PM, James Schneider wrote: Again, I'm making some assumptions about your models. If the above code snippets don't work (aside from typos), please post up your models.py file(s) so that we can adjust accordingly. I think James is right. Maybe the answer to the above question

Re: Absolute beginner question -- recipes

2016-02-28 Thread James Schneider
On Sun, Feb 28, 2016 at 12:23 PM, Simon Gunacker wrote: > Thank you Rahul, > > I actually tried that an this is possible for the relationship between a > recipe and its steps. But when it comes to the ingredients for a single > step, I cannot do this any more since the

Re: Absolute beginner question -- recipes

2016-02-28 Thread James Schneider
On Sun, Feb 28, 2016 at 11:47 AM, Rahul Gandhi wrote: > You could do something like this: > > def detail(request, pk): > recipe = Recipe.objects.get(id=pk) > steps = Steps.objects.filter(recipe_id=pk) > template =

Re: Absolute beginner question -- recipes

2016-02-28 Thread James Schneider
On Sun, Feb 28, 2016 at 11:14 AM, Simon Gunacker wrote: > Dear Django Community, > > as a first django project I tried to write a site to manage cooking > recipes. My model is quite simple: > > * 1 recipe has n steps > * 1 step has a description and n ingredients, each

Re: Absolute beginner question -- recipes

2016-02-28 Thread Simon Gunacker
Thank you Rahul, I actually tried that an this is possible for the relationship between a recipe and its steps. But when it comes to the ingredients for a single step, I cannot do this any more since the ingredients depend on steps again. After reading your suggestion I thought about it once

Re: Absolute beginner question -- recipes

2016-02-28 Thread Rahul Gandhi
You could do something like this: def detail(request, pk): recipe = Recipe.objects.get(id=pk) steps = Steps.objects.filter(recipe_id=pk) template = loader.get_template('recipe/recipe_detail.html') context = { 'recipe': recipe, 'steps': steps } return

Re: Absolute beginner question -- recipes

2016-02-28 Thread Rahul Gandhi
You could do something like this: Instead of recipe['steps'] = Steps.objects.filter(recipe_id=pk) Do this: steps = Steps.objects.filter(recipe_id=pk) context = { 'recipe': recipe, } On Monday, February 29, 2016 at 1:00:25 AM UTC+5:30, Simon Gunacker wrote: > > Dear Django

Absolute beginner question -- recipes

2016-02-28 Thread Simon Gunacker
Dear Django Community, as a first django project I tried to write a site to manage cooking recipes. My model is quite simple: * 1 recipe has n steps * 1 step has a description and n ingredients, each of a certain amount defined by a certain unit all in all, I have 5 tables (Recipe, Step,