Monday, August 27, 2018

Printing model fields organized by category

I have a Class called "Model" that has a field called "model_numbers". I have another class called "Category" that has a field called "category". In the Model Class, I have a field called category that is a Foreign Key to the field category in the Class category.

Screen Shot 2018-08-27 at 8.58.54 AM.png


Also, here is the html that prints the modeul_number and category fields:

Screen Shot 2018-08-27 at 9.01.10 AM.png



What the code is printing:

CATEGORY 1:
 - Field 1
 - Field 2
 - Field 3 

CATEGORY 2:
 - Field 1
 - Field 2
 - Field 3

What I want it to print is:

CATEGORY 1:
 - Field 1
 - Field 2

CATEGORY 2:
- Field 3

In this way it prints out all the model numbers under their respective category name (instead of all model numbers under every category, which is not correct as each model number only has one category). 


Thank you!

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
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/098cc4aa-374a-4e9a-9da1-ee49bab591aa%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment