Hi Rajesh,

Yes that worked, thanks for your help.

Regards,
Eamon

On Feb 1, 7:04 pm, Rajesh Dhawan <[EMAIL PROTECTED]> wrote:
> Hi,
>
> > I am new to django, please excuse any naivity.
>
> Welcome to Django :)
>
>
>
>
>
> > I would like to list
> > child and related parent records from the scenario below. Although
> > quite happily displaying ChildFile records, I can't seem to display
> > any ParentFile records.
>
> > models.py
> > class ParentFile(models.Model):
> >     recnum = models.AutoField(primary_key=True)
> >     number = models.FloatField(max_digits=12, decimal_places=0)
> >     date = models.DateField()
> >     time = models.CharField(maxlength=5)
> >     city = models.CharField(maxlength=40)
> >     country = models.CharField(maxlength=40)
> >     ...
>
> > class ChildFile(models.Model):
> >     docket = models.ForeignKey(ParentFile, related_name = 'number',
> > unique=True)
> >     recnum = models.TextField(unique=True) # This field type is a
> > guess.
> >     docket = models.FloatField(max_digits=12, decimal_places=0,
> > primary_key=True)
>
> You've two fields called docket in this model. That's not allowed.
> Rename one of them and regenerate your model.
>
>
>
>
>
> >     name = models.CharField(maxlength=40)
> >     date = models.DateField()
> >     ...
>
> > views.py
> > def Outstanding(request):
> >     fLatestRecs = ChildFile.objects.filter(name =
> > 'DAN').select_related().order_by('-date')
> >     return render_to_response('/report.html', {'fLatestRecs':
> > fLatestRecs })
>
> > report.html
> > ...
> > {% if fLatestRecs %}
> >         <table border="1" cellspacing="0" cellpadding="0"
> > width="100%">
> >                     <tr bgcolor="lightblue">
> >                         <td>Date</td>
> >                         <td>Time</td>
> >                         <td>Name</td>
> >                         <td>City</td>
> >                         <td>Country</td>
> >                     </tr>
> >             {% for ChildFile in fLatestRecs %}
> >                     <tr bgcolor="lightblue">
> >                         <td>{{ ChildFile.date }}</td>
> >                         <td>{{ ChildFile.time }}</td>
> >                         <td>{{ ChildFile.name }}</td>
> >                         <td>{{ ParentFile.city }}</td>
> >                         <td>{{ ParentFile.country }}</td>
>
> Change those two lines like this (assuming docket is your ForeignKey
> field to ParentFile):
>
> <td>{{ ChildFile.docket.city }}</td>
> <td>{{ ChildFile.docket.country }}</td>
>
> Basically, you can get to a parent object by traversing the relevant
> ForeignKey field of the child object instance. You might want to read
> up on the DB API documentation for more details on this.
>
> Also, it's a common convention to use titlecasing in class names and
> not in instance names. So, in your template, I would suggest renaming
> ChildFile to childfile or child_file.
>
> -Rajesh- Hide quoted text -
>
> - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to