django-related-manager

Django: How to get data connected by ForeignKey via Template?

一个人想着一个人 提交于 2019-11-30 14:55:36
问题 Since a few weeks I am learning Python and Django. Up to this point it has been enough to read the questions and the answers of other users.But now the moment of my first own question has come. I will try to describe my problem as best i can. My problem is that I cant query or get the data I want. I want to get the url of the first object of class Image which is associated by ForeignKey to a Gallery, which is associated by ForeignKey to the class Entry. Here the models.py so far: class

Django: How to get data connected by ForeignKey via Template?

心已入冬 提交于 2019-11-30 12:07:51
Since a few weeks I am learning Python and Django. Up to this point it has been enough to read the questions and the answers of other users.But now the moment of my first own question has come. I will try to describe my problem as best i can. My problem is that I cant query or get the data I want. I want to get the url of the first object of class Image which is associated by ForeignKey to a Gallery, which is associated by ForeignKey to the class Entry. Here the models.py so far: class BlogEntry(models.Model): ... title = models.CharField(max_length=100) ... class Gallery(models.Model): entry

Django ManyToMany relation to 'self' without backward relations

余生颓废 提交于 2019-11-30 11:44:04
There are several question about backwards relations here, but I'm either too dumb to understand them or think they don't fit my case. I have model class MyModel(models.Model) stuff = models.ManyToManyField('self', related_name = 'combined+') I have created form where i combine the information stored. And it stores object relations in database like that: Table: id:from_stuff_id:to_stuff_id 1:original_object_id:first_related_object 2:original_object_id:second_related_object 3:first_related_object:original_object_id 4:second_related_object:original_object_id So when i display object first

Django ManyToMany relation to 'self' without backward relations

你离开我真会死。 提交于 2019-11-29 17:24:27
问题 There are several question about backwards relations here, but I'm either too dumb to understand them or think they don't fit my case. I have model class MyModel(models.Model) stuff = models.ManyToManyField('self', related_name = 'combined+') I have created form where i combine the information stored. And it stores object relations in database like that: Table: id:from_stuff_id:to_stuff_id 1:original_object_id:first_related_object 2:original_object_id:second_related_object 3:first_related