Django Many-to-one relationships -


for question, i´ll using examples of django documentation.

my problem click reporter name , change webpage list of articles.

this models.py

from django.db import models    class reporter(models.model):      first_name = models.charfield(max_length=30)      last_name = models.charfield(max_length=30)      email = models.emailfield()        def __str__(self):              # __unicode__ on python 2          return "%s %s" % (self.first_name, self.last_name)    class article(models.model):      headline = models.charfield(max_length=100)      pub_date = models.datefield()      reporter = models.foreignkey(reporter, on_delete=models.cascade)        def __str__(self):              # __unicode__ on python 2          return self.headline        class meta:          ordering = ('headline',)

how can change 1 model other useing many-to-one relationship class-based views. https://docs.djangoproject.com/en/1.11/topics/db/examples/many_to_one/

thanks in advance

you can by

 {% article in reporter.article_set.all %}      {{article.headline}}      {{article.pub_date}}  {% endfor %} 

Comments

Popular posts from this blog

ios - MKAnnotationView layer is not of expected type: MKLayer -

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -