tags:

views:

29

answers:

1

Hey, Ive a problem referencing to my "THROUGH" m2m model extra fields. I can reference the linked model (User), but not the extra detail on the "through-model" (listuser)

My Model definition--- User model is the built in User model Untouched.

class joblist(models.Model):
    userdetail = models.ManyToManyField(User,through='userextra')

class userextra(models.Model):
    joblist = models.ForeignKey(joblist)
    user = models.ForeignKey(User)
    comments= models.CharField(max_length=16384, blank=True, null=True)

In my Template-----

{% for row in joblist %}
html here
{% for item in row.userdetail.all  %}
{{item.username}}-"I want to print comments here"
{% endfor %}
{% endfor %}

Ive tried {{item.userextra.comments}} {{item.comments}} {{item.douser.comments}}

So I am getting the detail from the "User" model but Im not getting the extra fields on the userextra model????

Any help appreciated.... N

A: 

You've got more backflip potential in the view than the template.

So, while it's an inelegant solution, I'd suggest querying the through model in the view directly and then using what you get back to temporarily annotate the items in the rows of your joblist appropriately so that you can definitely, cleanly, do row.foo.bar or item.baz.boof, etc, then pass that manually annotated set of results into the template.

stevejalim
Hmmm, not sure what you mean, Could you give an example?I already do some filtering in views, but that doesnt help displaying it in the template. I dont know how/if to rearrange the Queryset?
Niall