qamarali
This link will definitely help you out...I have a dictionary which contains one item (“current_location”, which is a nested dict) and I would like to access that nested dict. However, I cannot use the key as the code will break if a different key is passed, e.g. “different_location".
How can I access the first item in a dictionary without using a key? The dict looks like this:
{'current_location': {'date': '2020-01-27T10:28:24.148Z', 'type_icon': 'partly-cloudy-day', 'description': 'Mostly Cloudy', 'temperature': 68.28, 'wind': {'speed': 10.48, 'bearing': 178, 'gust': 12.47}, 'rain_prob': 0.02, 'latitude': '-33.927407', 'longitude': '18.415747', 'request_id': 31364, 'request_location': 'Current location'}}
I have these two models
class Project(models.Model):
project_name = models.CharField(max_length=100, blank=False)
description = models.TextField(max_length=500, default=None)
postedOn = models.DateTimeField(auto_now_add=True, blank=True)
Owner = models.ForeignKey(User, on_delete=models.CASCADE)
isCompleted = models.BooleanField(default=False)
deadline = models.DateTimeField(blank=True, null=True)
task_count = models.IntegerField(default=0)
attachments=models.FileField(default='Project Attachments', upload_to='tasks_docs', validators=[validate_file_extension])
def __str__(self):
return self.project_name
class Task(models.Model):
task_name = models.CharField(max_length=50, blank=False)
addedOn = models.DateTimeField(auto_now_add=True, blank=True)
project = models.ForeignKey(Project, on_delete=models.CASCADE, default=1)
rating = models.DecimalField(default=0, max_digits=2, decimal_places=1)
amount = models.IntegerField(default=0)
task_description = models.TextField(max_length=1000, default=None)
task_link = models.URLField(blank=True)
latest_submission_time = models.DateTimeField(blank=True, null=True)
isCompleted = models.BooleanField(default=False)
deadline = models.DateTimeField(blank=True, null=True)
task_attachments=models.FileField(default='Tasks To Do', upload_to='tasks_docs', validators=[validate_file_extension])
def __str__(self):
return self.task_name
And I am looking for a way to access tasks based on project. I can select a specific project and view its tasks
Hi, I have a quick question.
Say I have models called "Post" and "Reaction" and I have made a Post, saved it and now I want to react on it with a Reaction.
Now, when I visit my feed where a list of Posts is, I want to show my reaction if I had one.
Which means:{% if post.my_reaction %}{{ post.my_reaction.contents }}{% endif %}
Now, obviously I want to load more than just one Post; posts which don't have my reactions on it.
SELECT * FROM Post
LEFT JOIN Reaction ON Reaction.Post = Post.id
StreamingHttpResponse
for bundling, streaming React, etc.. and more easily