mercredi 19 février 2020

creating an if statement that checks the value of an obect and subsequently assigns a value to another object

news_categories = [ (ARCHEOLOGY, 'Archeology'), (CELEBRITYNEWS,'Celebrity News'), (CONFLICTS,'Conflicts'), (CRIME,'Crime'), (DISASTER,'Disaster'), (EDUCATION,'Education'), (ENVIRONMENT,'Environment'), (IMMIGRATION,'Immigration'), (MUSICNEWS,'Music News'), (NATURALSCIENCE,'Natural Science'), (RELIGION,'Religion'), (SCANDALS,'Scandals'), (WILDNATURE,'Wild Nature'),] category = models.CharField( max_length=15, choices=news_categories, default=ARCHEOLOGY, )

I have this code wich makes a dropdown of the list and assigns the value as a category when you make the post.

how do i make a variable to hold multiple choices from this list as another value?

Essentialy each item on the list link to page filled with posts containing that category (crime, religion etc..)

But how would i make an object called outer-category thats chosen when the category is chosen(i.e. when i choose religion as a category for a post, i want it to automatically add itself to an oitercategory called world

I would guess it involves and if statement? (If 'catergory'=='religion: 'outercategory'='world'

But that doesnt seem to be working for me.

Aucun commentaire:

Enregistrer un commentaire