Hi Mitch,

I haven't read through your example in detail, but just glancing over it I
think that I can see the mistake you're making

The problem is that there is no "number_list" key in your context, there is
only a "range" and "range_list" key (take a look at where you call
"render_to_response"). I think what you want to do is actually pass your
"net" variable into the template. Although your "net" variable doesn't
appear to have been defined anywhere in your view, so the code you've sent
us probably won't execute. Are all the calls you make to net.append()
supposed to be myrange.append() instead?

Chris

On Mon, Jun 8, 2009 at 11:46 AM, Mitch Anderson <xofre...@gmail.com> wrote:

>
> Below is what I have currently... it currently displays the numbers in
> the range its supposed to, but tying the products and displaying those
> where they should be in the number list has become the problem...
> One product can have multiple numbers associated, and I didn't want to
> fully populate every possible number combination for the range to save
> on disk space... as there will be thousands of possible numbers and
> maybe only a few hundred actually used...
>
> Heres what I have... what am I doing wrong?  is there a better way to
> handle the view?
>
> Models:
>
> class Range(models.Model):
>  lowerNum = models.IntegerField()
>  upperNum = models.IntegerField()
>  ...
>
> class Number(models.Model):
>  number = models.IntegerField()
>  range = models.foreignKey(Range)
>
> class Product(models.Model):
>  name = models.CharField()
>  description = models.CharField()
>  mynumbers = models.ManyToManyField(Number, blank=True, null=True)
>  ...
>
> view:
> def range_display(request, myrange):
>  r = get_object_or_404(Range, lowerNum=myrange)
>
>  myrange = []
>  range_list = generageRange(str(r.lowerNum), str(r.upperNum))
>  used_number_list = Number.objects.filter(range=r)
>
>  for a in range_list:
>      for b in used_number_list:
>          if str(b) == str(a):
>              try:
>                  prod = Product.objects.get(mynumbers__number=a)
>                  net.append({'num': a, 'name': prod.name,
> 'description': prod.description })
>              except:
>                  badnum = Number.objects.get(number=a)
>                  badnum.delete()
>                  net.append({'num': a })
>              break
>          else:
>              net.append({'num': a })
>              break
>     continue
>  return render_to_response('range_display.html', {'range': myrange,
> 'range_list': myrange, } )
>
> range_display.html template:
>
> <table>
>  <tr>
>    <th>number</th>
>    <th>name</th>
>    <th>description</th>
>  </tr>
>  {% for n in number_list %}
>    <tr>
>      <td>{{ n.num }}</td>
>      <td>{{ n.name }}</td>
>      <td>{{ n.description }}</td>
>    </tr>
>  {% endfor %}
> </table>
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to