On Saturday, 15 October 2011 15:12:17 UTC+1, Piotr Hosowicz wrote:
>
> Hello, 
>
> I still do not understand how things are connected in Django. In 
> models.py I have: 
>
> class CampaignManager(models.Manager): 
>     pass 
>
> class CampPeople(models.Model): 
>     person = models.ForeignKey(Person) 
>     camp = models.ForeignKey(Campaign) 
>     docall = models.BooleanField(True) 
>     called = models.BooleanField(False) 
>     objects = CampaignManager() 
>
> class Phone(models.Model): 
>     # person = models.ForeignKey(Person) 
>     phone = models.CharField(u"Telefon", max_length=255) 
>     def __unicode__(self): 
>         return "%s" % (unicode(self.phone) or "") 
>
> class PersonPhonesManager(models.Manager): 
>     pass 
>
> class PersonPhones(models.Model): 
>     person = models.ForeignKey(Person) 
>     phone = models.ForeignKey(Phone) 
>     objects = PersonPhonesManager() 
>     def __unicode__(self): 
>         return "%s" % (unicode(self.phone) or "") 
>
> In the template I have: 
>
> <table> 
>
> {% for piplok in camppeople %} 
> {% if piplok.docall %} 
>   <tr> 
>   <td>{{ piplok.person.label }} 
>   </td> 
>   <td> 
>   {{ personphones.phone }} 
>   </td> 
>   </tr> 
> {% else %} 
>   NOT 
> {% endif %} 
> {% endfor %} 
>
> </table> 
>
> And I do not see any  row output. 
>
> Please help, 
>
> Regards, 
>
> Piotr Hosowicz



Piotr,

Unfortunately, you have received a lot of very bad advice in this thread, 
for which I can only apologise on behalf of Django-users ...

The references to your custom Managers are misleading. Although it's true 
that you don't need them, because they're not changing anything, you aren't 
in fact breaking anything by having them - just defining them with a "pass" 
doesn't, as some people apparently think, mean that they now have no content 
- of course it doesn't, because you inherit from models.Manager, soo you'll 
have all the default code of that class. Still, as I say, because you don't 
change anything, you don't need them.

The main weird thing in the code you have posted is these two lines in the 
CampPeople model:

    docall = models.BooleanField(True) 
    called = models.BooleanField(False) 

Now, the first parameter to a model field (apart from ForeignKeys) is the 
verbose name - ie what appears as the prompt when you create a form based on 
that model. So it seems you have True and False as the verbose names, which 
I'm sure isn't what you want - but I'm not certain what it is you *do* 
intend here. Are you hoping that these will be the default values? If so, 
you need to use the `default` argument:

    docall = models.BooleanField(default=True) 
    called = models.BooleanField(default=False) 

Does that help at all?

You might also try putting some debugging into your template to see if 
you're getting the results you think you are:

    {% for piplok in camppeople %} 
        {{ piplok }}
        ...

--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/-mZF3n-I1xsJ.
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