Posts

Showing posts with the label django-templates

A List inside a list in django templates

A List inside a list in django templates How do you render a list of user who have a list of their own objects related with foreign-key in Models. When I render in html it brings all list of all users in all users, EDIT Sorry for late reply, I rarely get time to get to my computer, I have three models, Profile, Resume and Skills with the two related to Profile through foreign key... VIEWS.PY class ResumeList(ListView): model = User_Profile context_object_name = 'profile' template_name = 'resume/list.html' paginate_by = 6 def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['resume'] = Resume.objects.all() context['skill_list'] = Skill.objects.all() return context LIST.HTML {% extends "base.html" %} {% load static %} {% block content %} {% for obj in profile %} {{ obj.first_name }} {{ obj.last_name }} {% for obj in resume %} ...

django template tag missing 1 required positional argument : value

django template tag missing 1 required positional argument : value In my django project I have custom template tag to set correct next link in pagination : @register.tag(name='url_replace') def url_replace(request, field, value): print('this is form tag',request,field,value) d = request.GET.copy() d[field] = value return d.urlencode() In my template : {% if is_paginated %} <ul class="pagination pull-right"> {% if page_obj.has_previous %} <li><a href="?{% url_replace request 'page' page_obj.previous_page_number %}">&laquo;</a></li> {% else %} <li class="disabled"><span>&laquo;</span></li> {% endif %} {% for i in paginator.page_range %} {% if page_obj.number == i %} <li class="active"><span>{{ i }} <span class="sr-only">(curre...

Django ModelForm: How to Add ForeignKey as Field in Form?

Image
Django ModelForm: How to Add ForeignKey as Field in Form? I have Three Models StudentInfo , StdSubject , Marks class StdSubject(StdCommon): REGULAR='R' OPTIONAL='O' SUBJECT_TYPE_CHOICE=( (REGULAR, 'REGULAR'), (OPTIONAL, 'OPTIONAL') ) subject_name = models.CharField('Subject Name', max_length=100) subject_type = models.CharField( 'Subject Type', max_length=1, default=REGULAR, choices=SUBJECT_TYPE_CHOICE) subject_full_marks = models.DecimalField( 'Full Marks', max_digits=5, decimal_places=2, default=100) subject_pass_marks = models.DecimalField( 'Pass Marks', max_digits=5, decimal_places=2) def __str__(self): return self.subject_name class StudentInfo(StdCommon): STD_CLASS=( ('6','Six'), ('7','Seven'), ('8','Eight'), ('9','Nine'), (...