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