For loop with range in django template

How can i make a for loop with range function in django template? i want to search in three lists by using this structure. I tried this and it didn’t work: {% for i in range(number) %} {{ my_list.i }} {% endfor %} >Solution : You cannot simply use use Pythonic round brackets inside curly… Read More For loop with range in django template

Django form is not displaying all fields

I have a problem, i need to create form like scheme, i have my models and created forms.py.When i add my forms into the HTML, i have only 2 of all fields in my forms.What it can be? This is my models.py class Post(models.Model): full_name = models.CharField(max_length=60, verbose_name=’Full name’), name_scheme = models.CharField(max_length=40, verbose_name=’Name of scheme’)… Read More Django form is not displaying all fields

Using related_name in Django Template

I have two models: Usecase and Usecase_progress. I’m creating a page where I can see a list of all the use cases with their information + the usecase progress for each use case. Usecase model: class Usecase(models.Model): usecase_id = models.CharField(primary_key=True, max_length=20) usecase_name = models.CharField(max_length=256) user_email = models.ForeignKey(‘User’, models.DO_NOTHING, db_column=’user_email’) usecase_type = models.ForeignKey(‘UsecaseType’, models.DO_NOTHING) kpi =… Read More Using related_name in Django Template

custom message if there isnt any record to show in django-template

Hello there im trying to show a custom message like "Doesnt exists" if there isnt really any record to show and ignore having None in the template for empty records Template : <div class="col-md-6 col-sm-12 col-xs-12 form-group pull-right "> <label style="color : blue;" class="control-label col-md-5 col-sm-3 col-xs-12 pull-right size_Style"><i class="fa fa-circle" style="color : blue;" aria-hidden="true"></i>… Read More custom message if there isnt any record to show in django-template

Syntax for using {{ article.image }} inside {% static %} with django templates

Trying to display an image on a webpage with django templates {% for article in article_roll %} <li><div class="blog-post" id="blog{{ forloop.counter }}"> {% load static %} <img src="{% static ‘{{ article.image }}’ %}" alt="{{ article.alt }}"> <div class="blog-post-preview"> <span class="blog-title">{{ article.image }} {{ article.title }}</span> <span class="blog-date">{{ article.date }}</span> </div> <span class="blog-text">{{ article.preview }}</span> </div></li>… Read More Syntax for using {{ article.image }} inside {% static %} with django templates

How to detect change in HTML page after a successful redirect from form?

views.py class ChangePasswordView(PasswordChangeView): form_class = ChangePasswordForm success_url = reverse_lazy("login") login.html {% if XXXXXX %} <p style="color:green;">Password changed successfully! Please login.</p> {% endif %} Basically I want the following message to appear on my login html page if password was changed. Is there a way to detect if form was successful (by passing some parameter to… Read More How to detect change in HTML page after a successful redirect from form?

Access Foreign Key count in Django Template

I have two models: Farm and Animal with a ForeignKey relation. Each Farm contains x animals. I’m doing a table in the frontend with a for loop of each farm. How can I show the number of animals in each farm? models: class Farm(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, blank=True, null=True, default=None) square_meter = models.IntegerField(blank=True, null=True)… Read More Access Foreign Key count in Django Template

model form not rendering in django template

My models.py and this is my model for photos. # home photo page class Photos(models.Model): photo_title = models.CharField(max_length=50, blank=False) photo_description = models.CharField(max_length=50, blank=False) photo_date = models.DateField(blank=False) photo_location = models.CharField(max_length=50, blank=False) photo_file = models.FileField(upload_to=’photos’, blank=False) def __str__(self): return self.photo_title My forms.py this is the model form I made to render it as a form. class UploadPhotosForm(forms.Form):… Read More model form not rendering in django template