How to customise Folium html popups in a for loop in python using .format()?

I am trying to change the standard popups provided with Folium and make these work with a for loop. I am using Django. I succeeded on change the html, following a few tutorials. However I am struggling to understand how to call the variables in the html. Quite simply I have a map with a… Read More How to customise Folium html popups in a for loop in python using .format()?

Why the first() method and slices works differently in Django?

I have the model: class PhotoAlbum(models.Model): id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False, auto_created=True) name = models.CharField(max_length=50, verbose_name=’Album name’) type = models.ForeignKey(AlbumType, on_delete=models.CASCADE, verbose_name=’Album type’) created_at = models.DateTimeField(auto_now_add=True) And i have this code: print(PhotoAlbum.objects.all().first()) print(PhotoAlbum.objects.all()[:1].get()) it seemed to me that the same objects should be displayed, but different ones are returned. What’s going on, isn’t it an… Read More Why the first() method and slices works differently in Django?

Showing two model in same page Django

I have two models: class Post(models.Model): title= models.CharField(max_length=255) author = models.ForeignKey(User, on_delete=models.CASCADE) body = models.TextField() postimage = models.ImageField(null= True, blank= True, upload_to="images/") created_date = models.DateTimeField(default=timezone.now) published_date = models.DateTimeField(blank=True, null=True) def publish(self): self.published_date = timezone.now() self.save() def __str__(self): return self.title + " | "+ str(self.author) def get_absolute_url(self): return reverse(‘article_deatil’, args=(str(self.id))) class AboutMe(models.Model): title1= models.CharField(max_length=255, default="About Me")… Read More Showing two model in same page Django

How to Count quantity of my QuerySet. Django

Well, i have the following function: employees_birthday = Employees.objects.filter(EmployeeDataNasc__gte=first_day, EmployeeDataNasc__lte=last_day) It serves to return employees born between the dates. She returns: <QuerySet [<Employees: Alberto Santos>, <Employees: Josney Arman>]> But, I would just like to display the number of employees in the QuerySet, i.e. make a Count function. Can someone help me with the syntax? >Solution… Read More How to Count quantity of my QuerySet. Django

How to sort distinct values with respect to manytoone class in Django?

I have two models class MessageThread(models.Model): title = models.CharField(max_length=120, blank=True, null=True) created_user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, related_name=’created_user’) belonging_user = models.ForeignKey(User, on_delete=models.SET_NULL, null=True) last_message_date = models.DateTimeField(blank=True, null=True) and class Message(models.Model): thread = models.ForeignKey(MessageThread, on_delete=models.SET_NULL, null=True) user = models.ForeignKey(User, null=True, blank=True, on_delete=models.SET_NULL) comments = models.TextField(blank=True, null=True, max_length=500) create_date = models.DateTimeField(blank=True, null=True) Here, I want to get MessageThreads… Read More How to sort distinct values with respect to manytoone class in Django?

django queryset filter on whether related field is empty

here is my models: class Flag(models.Model): ban = models.ForeignKey(‘flags.Ban’, on_delete=models.CASCADE, related_name=’flags’) class Ban(models.Model): punished = models.BooleanField(default=None) Flag is triggered when user report some content. and they are summarised in to a Ban instance for administrator to verify. briefly, a ban can have many flags. there is one occasion, that the author getting reported, manually deletes… Read More django queryset filter on whether related field is empty

How to filter the dates from datetime field in django

views.py import datetime from django.shortcuts import render import pymysql from django.http import HttpResponseRedirect from facligoapp.models import Scrapper from django.utils import timezone import pytz roles = "" get_records_by_date = "" def index(request): if request.method == "POST": from_date = request.POST.get("from_date") f_date = datetime.datetime.strptime(from_date,’%Y-%m-%d’) print(f_date) to_date = request.POST.get("to_date") t_date = datetime.datetime.strptime(to_date, ‘%Y-%m-%d’) print(t_date) global get_records_by_date get_records_by_date = Scrapper.objects.all().filter(start_time=f_date,end_time=t_date)… Read More How to filter the dates from datetime field in django