Thanks for replying to my question.
What I am trying to do is for each building in the list see if there is a
corresponding address record for that building. Thus I'm trying to test the
opposite of what you've pointed out i.e. not that there will be an address
without a building, but if that building has an address.
On Thursday, 26 January 2017 19:21:18 UTC+11, ludovic coues wrote:
>
> You are assuming you can have address without building.
> {% if x.building %}
>
> 2017-01-26 0:27 GMT+01:00 Richard Hall <[email protected] <javascript:>>:
>
> > Hello, I've only just started with Django and need a bit of help
> steering
> > myself in the right direction.
> >
> > I want to create a page that has a list of possible forms that could be
> > filled in for a patient in a medical study and differentiate between
> those
> > forms which have already been completed and those that have yet to be
> > started. I have 3 tables: 'Building' which contains the list of forms,
> > 'Street' which contains the list of patients and 'Address' which records
> > which form exists for each patient. The relevant bit of models.py looks
> like
> > this:
> >
> > class Building(models.Model):
> > crf_code = models.CharField(max_length=6, primary_key=True)
> > crf_name = models.CharField(max_length=100)
> >
> > class Street(models.Model):
> > village = models.ForeignKey(Village)
> > patient_number = models.PositiveIntegerField()
> > initials = models.CharField(max_length=3)
> >
> >
> > class Address(models.Model):
> > street = models.ForeignKey(Street, related_name='addresses')
> > building = models.ForeignKey(Building, related_name='addresses')
> > completed = models.BooleanField(default=False)
> >
> > I've created a view that creates two lists, one of all buildings (i.e.
> forms
> > that could be entered for a patient) and another of forms already
> existing,
> > filtered by patient id:
> >
> > def street2(request, patientid):
> > context_dict = {}
> > try:
> > address = Address.objects.filter(street__pk=patientid)
> > crf = Building.objects.all()
> > context_dict['address'] = address
> > context_dict['crf'] = crf
> > except Street.DoesNotExist:
> > context_dict['address'] = None
> > context_dict['crf'] = None
> >
> > return render(request, 'trial/street2.html', context_dict)
> >
> > My problem comes with relating the two lists to each other in my
> template.
> > what I want to do is list the buildings and then, depending if the form
> > already exists, display an "edit form" or "create form" link:
> >
> > <div>
> > <ul>
> > {% for x in address %}
> > <li>
> > <div>{{ x.building }}</div>
> > <div>
> > {% if ???? %}
> > link to edit form
> > {% elif %}
> > link to create form
> > {% endif %}
> > </div>
> > </li>
> > {% endfor %}
> > </ul>
> > </div>
> >
> > I'm not sure if I've explained myself clearly; if not I apologize. I'm
> only
> > just starting out and am floundering a bit. Any help or guidance would
> be
> > hugely appreciated.
> >
> > Thank you,
> >
> > Richard
> >
> > --
> > 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 [email protected] <javascript:>.
> > To post to this group, send email to [email protected]
> <javascript:>.
> > Visit this group at https://groups.google.com/group/django-users.
> > To view this discussion on the web visit
> >
> https://groups.google.com/d/msgid/django-users/237bb16a-d76e-42b9-bd46-a7b2f9c43f4c%40googlegroups.com.
>
>
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
>
> Cordialement, Coues Ludovic
> +336 148 743 42
>
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/0ea9674b-caef-479a-a51e-3b6e544615d7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.