Hello,

I don't know if you've changed names to protect the innocent, but conceptually, 
these 
models are hard to translate to the real world. This is the opposite of what 
object 
oriented programming is trying to accomplish and probably why you're having a 
hard 
time figuring it out and explaining to others.

For example, it makes no sense that a street has a patient number and initials. 
Address should be a through model for a ManyToManyField on Building (if we're 
talking 
buildings, addresses and streets and ignore patients), but then "completed" 
isn't a 
good way to distinguish between "23 Main Road" and "25 Main Road".

You get the idea...

>From the looks of it, you altered your code (street_pk=patientid should not 
>work as 
you think, as patient_number is not the pk of Street). If you do that - please 
use an 
anology that makes sense, possibly using the classics like fruits, books and 
pizzatoppings.

On Wednesday 25 January 2017 15:27:00 Richard Hall wrote:

> 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 %}

But...You're not listing buildings. You're listing addresses. So all buildings 
that come up, 
exist.
Figuring out the buildings "owned by" the patient which don't have addresses, 
you 
should iterate the buildings and inspect the addresses attribute. For ease of 
use in 
template, one could do this:

class Building(models.Model):
        # ....
        @property
        def has_address_for_patient(self):
                return hasattr(self, 'addresses') and \
                        
self.addresses.filter(street__pk=patientid).count() > 0

Remember that Django Template Language strives to keep programming out of the 
template, so either do the above in your model or in your view when building 
the 
context.
-- 
Melvyn Sopacua

-- 
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/3384291.oJKR40FGvU%40devstation.
For more options, visit https://groups.google.com/d/optout.

Reply via email to