How to display custom results in django?

Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
There are three models:
# Model event class Event(models.Model): title = models.CharField("event Name", max_length=25) location = models.CharField("Location", max_length=25) # Model of a simple blog post class Post(models.Model): title = models.CharField("post Title", max_length=50) body = models.TextField("Text post", blank=True, null=True) pub_date = models.DateTimeField("date published", # Model post tied to a specific event class EventPost(Post): event = models.ForeignKey(Event, on_delete=models.CASCADE)

The bottom line is that you need the blog to display all posts (related to the t. and simple) by date, but by posts from the events in the template is added to the die with the name of the event and place. I.e. you can merge two queries and pass to the template, but can't figure out how to get the dice values from the model outputs.
Came to mind the option to make in the model property EventPost something
@property def location(self): location = Event.objects.get(pk=self.event)

But I think it's not a very good option (and not the fact that working))
by | 10 views

1 Answer

0 like 0 dislike
1. event_post.event.location
2. EventPost is not the best solution, better Event to make a ForeignKey to Post, or Vice versa, there should be links from the start.
3., it is better auto_now_add=True

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
4 answers
0 like 0 dislike
1 answer
asked Mar 24, 2019 by xmdy
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
35,535 users