How to increment variable in Django template? - python

I was making a grid and need to declare the variable and increment it.
{% for new, des, i, link, published, author in mylist %}
{% if x == 1 %}
<div class="col-md-6">
<div class="h-100 mt-2 row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
<div class="col p-4 d-flex flex-column position-static">
<strong class="d-inline-block mb-2 text-primary">World</strong>
<h5 class="mb-0">{{new}}</h5>
<div class="mb-1 text-muted">{{published}}</div>
<p class="card-text mb-auto">{{des}}</p>
Continue reading
</div>
<div class="col-auto d-none d-lg-block">
<img class="bd-placeholder-img" src="{{i}}" width="200" height="250" >
</div>
</div>
</div>
{% endif %}
{% endfor %}
Help me to declare variable x and increment it like x+1 inside the template
I was trying {% with x=0 %} but that's not working

Try this below:
{% set x = 0 %}
{% for new, des, i, link, published, author in mylist %}
{% set x = x + 1 %}
{% if x == 1 %}
<div class="col-md-6">
<div class="h-100 mt-2 row no-gutters border rounded overflow-hidden flex-md-row mb-4 shadow-sm h-md-250 position-relative">
<div class="col p-4 d-flex flex-column position-static">
<strong class="d-inline-block mb-2 text-primary">World</strong>
<h5 class="mb-0">{{new}}</h5>
<div class="mb-1 text-muted">{{published}}</div>
<p class="card-text mb-auto">{{des}}</p>
Continue reading
</div>
<div class="col-auto d-none d-lg-block">
<img class="bd-placeholder-img" src="{{i}}" width="200" height="250" >
</div>
</div>
</div>
{% endif %}
{% endfor %}

django has a {{ forloop.counter }}. You can use this.

Related

How can I put an if in html so that the value of 'object.star' is equal to 1 and 2 at the same time

I tried this methods (with 'and, or' between two values)but 'and' only applies the first value('four')
Only in this way could I solve the problem by setting two separate 'ifs' for both, that this is not the right way
This is my code:
{% for object in object_list %}
**{% if object.star == "four" or "five" %}**
<div class="col mb-5">
<div class="card h-100">
<!-- Product image-->
<img class="card-img-top">{{object.thumbnail_tag}}
<!-- Product details-->
<div class="card-body p-4">
<div class="text-center">
<!-- Product name-->
<h5 class="fw-bolder">{{object.name}}</h5>
<!-- Product reviews-->
<div class="d-flex justify-content-center small text-warning mb-2">
{% if object.star == "four" %}
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
{% elif object.star == "five" %}
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
<div class="bi-star-fill"></div>
{% endif %}
</div>
<!-- Product price-->
{% if object.newprice == none %}
{{object.currency}}{{object.price}}
{% else %}
<span class="text-muted text-decoration-line-through">{{object.currency}}{{object.price}}</span>
<span style="color: #ffc107;">{{object.newprice}}</span>
{% endif %}
</div>
</div>
<!-- Product actions-->
<div class="card-footer p-4 pt-0 border-top-0 bg-transparent">
<div class="text-center"><a class="btn btn-outline-dark mt-auto" href="#">Add to cart</a></div>
</div>
</div>
</div>
{% endif %}
{% endfor %}
object.star == 'four' or 'five' doesn't do what you think.
It will first consider object.star == 'four' which is either True or False. If False it will then consider five (which is truthy).
You need to explicitly do 2 tests:
object.star == 'four' or 'object.star == 'five'

Display multiple list in django template

I have 10 lists of same lenght (20) with chained data meaning that A[0] is image for B[0] and C[0] but for the sake of smallest reproducible example i have 3
A=[image1, image2, image3, image4, image5, image6]
B=[title1, title2, title3, title4, title5, title6]
C=[name1, name2, name3, name4, name5 ,name6]
I need to dispaly them in Django Templates like this:
<div class="row">
<div class="col-4">
<div class="image">
image1
</div>
<div class="title">
title1
</div>
<div class="name">
name1
</div>
</div>
<div class="col-4">
<div class="image">
image2
</div>
<div class="title">
title2
</div>
<div class="name">
name2
</div>
</div>
<div class="col-4">
<div class="image">
image3
</div>
<div class="title">
title3
</div>
<div class="name">
name3
</div>
</div>
</div>
and after this row is next one will be generated with the rest of the values
How can i do this
Use zip
Ex:
def yorufunc(request):
A=[image1, image2, image3, image4, image5, image6]
B=[title1, title2, title3, title4, title5, title6]
C=[name1, name2, name3, name4, name5 ,name6]
context = {"data": zip(A, B, C)}
return render(request, 'yorufunc.html', context)
In Template
<div class="row">
{% for i, t, n in data %}
<div class="col-4">
<div class="image">
{{ i }}
</div>
<div class="title">
{{ t }}
</div>
<div class="name">
{{ n }}
</div>
</div>
{% endfor %}
</div>
another way would be, by using index templatetags
in your app folder create one folder, named templatetags
there create a file index.py :
from django import template
register = template.Library()
#register.filter
def index(indexable, idx):
return indexable[idx]
now it's better to restart your server once.
then in html do:
{% load index %}
<div class="row">
{% for x in A %}
<div class="col-4">
<div class="image">
{{x}}
</div>
<div class="title">
{{ B|index:forloop.counter0 }}
</div>
<div class="name">
{{ C|index:forloop.counter0 }}
</div>
</div>
{% endfor %}
</div>

Django templates don't show my all parameters

I have problem. I want create relationship in model Django. I would like every user to have a different product price. The product must be assigned to the user. It must is to display only after logging in. Unfortunately, the template does not show all parameters.
offers/models.py
class Product(models.Model):
title = models.CharField(max_length=100)
category = models.CharField(max_length=50)
weight = models.FloatField()
description = models.TextField(blank=True)
photo = models.ImageField(upload_to='photos/%Y/%m/%d/')
is_published = models.BooleanField(default=True)
list_date = models.DateField(default=datetime.now, blank=True)
def __str__(self):
return self.title
class UserProduct(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
title = models.ForeignKey(Product, on_delete=models.DO_NOTHING)
price = models.FloatField()
is_published = models.BooleanField(default=True)
list_date = models.DateField(default=datetime.now, blank=True)
def __str__(self):
return str(self.user.username) if self.user.username else ''
Products are to be displayed for logged in users.
offers/views.py
def index(request):
context = {
'products': Product.objects.order_by('category').filter(is_published=True)
}
return render(request, 'offers/products.html', context)
def userproduct(request):
context = {
'userproduct': UserProduct.objects.filter(user_id=request.user.id),
'userproduct1': Product.objects.all()
}
return render(request, 'offers/userproducts.html', context)
My template show only title, and price.
offers/userproducts.html
<!-- Offers -->
<section class="text-center mb-4 py-4">
<div class="container">
<div class="row">
{% if user.is_authenticated %}
{% if userproduct %}
{% for product in userproduct %}
<!--Grid column-->
<div class="col-lg-3 col-md-6 mb-4">
<div class="card">
<div class="view overlay">
<img src="{{ product.photo.url }}" class="card-img-top" alt="">
<a href="{% url 'product' product.id %}">
<div class="mask rgba-white-slight"></div>
</a>
</div>
<div class="card-body text-center">
<h6 class="grey-text">{{ product.category }}</h6>
<h5>
<strong>
{{ product.title }}
</strong>
</h5>
<h4 class="font-weight-bold colores">
<strong>{{ product.price }}</strong>
</h4>
</div>
</div>
</div>
<!--Grid column-->
{% endfor %}
{% else %}
<div class="col-sm-12 sm-12">
<p>No Products Available XD</p>
</div>
{% endif %}
{% endif %}
</div>
</div>
</section>
The userproduct queryset that you are iterating over belongs to UserProduct model which doesn't have the fields you're looking for.
This is how it should be:
<!-- Offers -->
<section class="text-center mb-4 py-4">
<div class="container">
<div class="row">
{% if user.is_authenticated %}
{% if userproduct %}
{% for product in userproduct %}
<!--Grid column-->
<div class="col-lg-3 col-md-6 mb-4">
<div class="card">
<div class="view overlay">
<img src="{{ product.title.photo.url }}" class="card-img-top" alt="">
<a href="{% url 'product' product.title.id %}">
<div class="mask rgba-white-slight"></div>
</a>
</div>
<div class="card-body text-center">
<h6 class="grey-text">{{ product.title.category }}</h6>
<h5>
<strong>
{{ product.title.title }}
</strong>
</h5>
<h4 class="font-weight-bold colores">
<strong>{{ product.price }}</strong>
</h4>
</div>
</div>
</div>
<!--Grid column-->
{% endfor %}
{% else %}
<div class="col-sm-12 sm-12">
<p>No Products Available XD</p>
</div>
{% endif %}
{% endif %}
</div>
</div>
</section>
If you need a field from Product model, you should get the Product instance which is title. So:
Price: product.price
Title: product.title.title (product.title also works because of your __str__ function.)
Category: product.title.category
Photo: product.title.photo
And so on ...

Django formtools with custom template

I have the following custom wizard
<div class="container">
<div id="smartwizard">
<ul>
<li>Engagement Setup<br /><small>Basic info</small></li>
<li>File Upload<br /><small>Upload files</small></li>
<li>Business Rules<br /><small>rules</small></li>
<li>Documentation<br /><small>documentation</small></li>
</ul>
<div>
<div id="step-1" class="">
<div id="form-step-0" role="form" data-toggle="validator">
<div class="form-group">
<label for="text">Code <span class="tx-danger">*</span></label>
<input type="text" class="form-control" name="code" id="code" placeholder="Write your code" required>
<div class="help-block with-errors"></div>
</div>
</div>
<hr />
</div>
....
</div>
</div>
<br />
</div>
I have setup the django form as such
class PageOne(forms.Form):
ibs_code = forms.CharField(max_length=100)
engagement_name = forms.CharField(max_length=100)
engagement_manager = forms.CharField(max_length=100)
engagement_partner = forms.CharField(max_length=100)
solution = forms.CharField(label='What solution would you like to use?', widget=forms.Select(choices=FRUIT_CHOICES))
And of course the views..
class TestWizard(SessionWizardView):
file_storage = FileSystemStorage(
location=os.path.join(settings.MEDIA_ROOT, 'temp_uploads'))
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.is_done = False
def get_template_names(self):
if self.is_done:
# return [self.templates['done']]
return [TEMPLATES['done']]
else:
return [TEMPLATES[self.steps.current]]
.....
......
Now I want to use the custom template with the form. Meaning, I want to generate the form fields the way the html/style looks with form-group and such. How can I achieve this?
I tried the documentation but they weren't any sources for custom templating
Update #1: Doing something like this is not sufficient
<div id="form-step-0" role="form">
<div class="form-group">
{% if wizard.form.forms %}
{{wizard.form.management_form }}
{% for form in wizard.form.forms %}
{{form}}
{% endfor %}
{% else %}
{{ wizard.form }}
{% endif %}
</div>
</div>
I need it to look just like the html I put together
First, you can specify the class to be used for your form fields, for example:
class PageOne(forms.Form):
ibs_code = forms.CharField(
max_length=100,
widget=forms.TextInput(
attrs={'class' : 'YourClassName'}
)
)
Second, you can put the individual fields within the template as you want
<div class="container">
<div id="smartwizard">
<ul>
<li>Engagement Setup<br /><small>Basic info</small></li>
<li>File Upload<br /><small>Upload files</small></li>
<li>Business Rules<br /><small>rules</small></li>
<li>Documentation<br /><small>documentation</small></li>
</ul>
<form>
{{ wizard.form.management_form }}
{% csrf_token %}
<div>
<div id="step-1" class="">
<div id="form-step-0" role="form" data-toggle="validator">
<div class="form-group">
<label for="text">Code <span class="tx-danger">*</span></label>
{{ form.ibs_code }}
{{ form.ibs_code.errors }}
</div>
</div>
<hr />
</div>
....
</div>
</form>
</div>
<br />
</div>
EDIT - ACTUAL LIVE EXMAPLE
<form id="" class="max-width-800px margin-center" action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ wizard.management_form }}
{{ wizard.form.media }}
<input name="job-is_user" type="checkbox" hidden {% if request.user.is_authenticated %}checked{% endif %}>
<input name="job-is_company" type="checkbox" hidden {% if request.user.company_user %}checked{% endif %}>
<div class="form-group">
<label for="id_job-plan_"PLANS[0].id >Job Listing Type</label>
{{ wizard.form.plan }}
<div class="alert alert-primary top-3">Jobs are subscription-based and are active until you've filled the position. At the end of your recurring billing cycle you will be charged and your listing will be moved back to the top of its category.</div>
</div>
<div class="form-group row">
<div class="col-6">
<label for="id_job-title">Job Title</label>
{{ wizard.form.title }}
</div>
<div class="col-6">
<label for="id_job-category">Job Category</label>
<span class="form-select">
{{ wizard.form.category }}
</span>
</div>
</div>
<div class="form-group">
<label for="">Job Type</label>
<div class="row">
{% for employment in EMPLOYMENTS %}
<div class="col-4">
<span class="form-radio form-radio-lg">
<input type="radio" id="id_job-employment_{{employment.id}}" name="job-employment" value="{{ employment.id }}" required {% if job.employment.id == employment.id or wizard.form.employment.value|add:"0" == employment.pk %}checked{% endif %}>
<label for="id_job-employment_{{employment.id}}">{{ employment }}</label>
</span>
</div>
{% endfor %}
</div>
</div>
<div class="form-group row">
<div class="col-6">
<label for="id_job-job_level">Job Level</label>
<span class="form-select">
{{ wizard.form.job_level }}
</span>
</div>
<div class="col-6">
<label for="id_job-salary_range">Job Compensation</label>
<span class="form-select">
{{ wizard.form.salary_range }}
</span>
</div>
</div>
<div id="job-location-groupX" class="form-group">
<label for="id_job-office_base">Job Location</label>
<div class="row">
{% for office in OFFICE_BASE %}
<div class="col-6">
<span class="form-radio form-radio-lg">
<input type="radio" id="id_job-office_base_{{office.id}}" name="job-office_base" value="{{ office.id }}" {% if job.office_base.id == office.id or wizard.form.office_base.value|add:"0" == office.pk %}checked{% endif %}>
<label for="id_job-office_base_{{office.id}}">{{ office.name }}</label>
</span>
</div>
{% endfor %}
</div>
<div id="new-job-location-details" class="hidden top-1">
{{ wizard.form.outside_location }}
{{ wizard.form.outside_location.errors }}
<ul class="list-unstyled list-increase-spacing">
<li>
<span class="form-checkbox">
{{ wizard.form.relocation_assistance }}
<label id="label-id_job-relocation_assistance" for="id_job-relocation_assistance">Relocation assistance provided</label>
{{ wizard.form.relocation_assistance.errors }}
</span>
</li>
<li>
<span class="form-checkbox">
{{ wizard.form.visa_sponsorship }}
<label for="id_job-visa_sponsorship">Visa sponsorship provided</label>
{{ wizard.form.visa_sponsorship.errors }}
</span>
</li>
</ul>
</div>
</div>
<div class="form-group">
<label for="id_job-description">Job Description</label>
<div class="col-12">
{{ wizard.form.description }}
{{ wizard.form.description.errors }}
</div>
</div>
<div id="job-how-to-apply-groupX" class="form-group">
<label>How to Apply to This Job</label>
<div class="row">
<div class="col-6">
<span class="form-radio form-radio-lg">
<input type="radio" required id="new-job-apply-us" value="4" name="job-apply_online" {% if job.apply_online == 4 or wizard.form.apply_online.value|add:"0" == 4 %}checked {% endif %}>
<label for="new-job-apply-us">Through us <em class="float-right tablet-hide">(recommended)</em></label>
</span>
</div>
<div class="col-6">
<span class="form-radio form-radio-lg">
<input type="radio" id="new-job-apply-you" name="job-apply_online" value="3" {% if job.apply_online == 3 or wizard.form.apply_online.value|add:"0" == 3 %}checked {% endif %}>
<label for="new-job-apply-you">Through you <em class="float-right tablet-hide">(external URL)</em></label>
</span>
</div>
</div>
<div id="new-job-apply-details" class="hidden top-1">
{{ wizard.form.apply_url }}
{{ wizard.form.howto_apply }}
</div>
</div>
<div id="job-extras" class="form-group">
<h6>Additional Extras <span class="optional-field">(optional)</span></h6>
{{ wizard.form.addons }}
</div>
<button type="submit" class="btn btn-lg btn-solid-teal">{% if request.user.company_user %}Preview Your Listing{% elif request.user.is_authenticated %}Enter Company Details{% else %}User Details{% endif %} →</button>
</form>
forms.py
class JobPostWizardForm1(forms.ModelForm):
error_css_class = "alert alert-error"
category = forms.ModelChoiceField(Category.objects.all(), empty_label='Choose one...', required=False)
job_level = forms.ModelChoiceField(JobLevel.objects.all(), empty_label='Choose one...', required=False)
salary_range = forms.ModelChoiceField(Salary.objects.active(), empty_label='Choose one...', required=False)
plan = forms.ModelChoiceField(Plan.objects.all(), empty_label=None, required=True, widget=PlanSelect)
is_user = forms.BooleanField(required=False)
is_company = forms.BooleanField(required=False)
class Meta:
model = Job
fields = [
'plan','title','category','employment','job_level','salary_range','office_base', 'outside_location',
'relocation_assistance','visa_sponsorship','description','apply_online','howto_apply','addons', 'is_user',
'is_company', 'apply_url'
]
def __init__(self, is_active= False, edit_mode=False, plan=0, *args, **kwargs):
super().__init__(*args, **kwargs)
self.fields['plan'].initial = Plan.objects.all()[plan]
if is_active : self.fields['plan'].widget.attrs['disabled'] = True
self.fields['description'].required = True
self.fields['apply_url'].widget.attrs['placeholder'] = 'External URL'
self.fields['howto_apply'].widget = forms.Textarea()
self.fields['howto_apply'].widget.attrs['rows']=10
self.fields['howto_apply'].widget.attrs['placeholder']="Additional instructions..."
self.fields['relocation_assistance'].widget = AuthenticJobsCheckbox()
self.fields['visa_sponsorship'].widget = AuthenticJobsCheckbox()
self.fields['addons'].widget = AddOnCheckboxSelectMultiple()
self.fields['addons'].queryset = AddOnItem.objects.filter(active=True)
#if edit_mode : self.fields['addons'].widget.attrs['disabled'] = True
if is_active : self.fields['addons'].widget.attrs['onclick'] = "return false;"
self.error_class = DivErrorList

data did'nt validate error django

Can anyone please help me..... I keep on getting "data didn't validate" error when saving data from a ModelForm. Everything worked fine for me until I added some CSS and JS for the frontend, used form widgets and manually displayed the form field on the template.
Here are the codes:
forms.py
from django import forms
from .models import List_of_Res
class fordtp(forms.Form):
month_choices=(
('JAN','January'),
('FEB','February'),
('MAR','March'),
('APR','April'),
('MAY','May'),
('JUN','June'),
('JUL','July'),
('AUG','August'),
('SEP','September'),
('NOV','November'),
('DEC','December'),
)
day_choices=[]
for ddd in range(1,32):
day_toS=(str(ddd),str(ddd))
day_choices.append(day_toS)
year_choices=[]
for yyy in range(1990,2100):
year_toS=(str(yyy),str(yyy))
year_choices.append(year_toS)
month = forms.ChoiceField(choices = month_choices,widget=forms.Select(attrs={'class':'form-control form-control-sm'}))
year = forms.ChoiceField(choices = year_choices,widget=forms.Select(attrs={'class':'form-control form-control-sm'}))
day = forms.ChoiceField(choices = day_choices,widget=forms.Select(attrs={'class':'form-control form-control-sm'}))
class ResearchForm(forms.ModelForm):
class Meta:
model = List_of_Res
fields={
'prog_title',
'proj_title',
'stud_title',
'prog_lead',
'stud_lead',
'co_res',
'res_site',
'campus',
'category_res',
'classif_res',
'amt_granted',
'date_started',
'res_status',
'date_completed',
'res_SF',
'res_pubstat',
'res_JN',
'res_JV',
'date_pub',
'res_iprstat',
'apptype',
'date_appl',
'date_pprv',
'app_pending',
'res_abs'
}
widgets = {
'prog_title': forms.TextInput(attrs={'class':'form-control'}),
'proj_title': forms.TextInput(attrs={'class':'form-control'}),
'stud_title': forms.TextInput(attrs={'class':'form-control'}),
'prog_lead': forms.TextInput(attrs={'class':'form-control'}),
'stud_lead': forms.TextInput(attrs={'class':'form-control'}),
'co_res': forms.Textarea(attrs={'class':'form-control','placeholder':'Enter 1 name per line'}),
'res_site': forms.Textarea(attrs={'class':'form-control','placeholder':'Enter 1 site per line'}),
'campus': forms.Select(attrs={'class':'form-control'}),
'category_res': forms.RadioSelect(attrs={'class':'form-check-input'}),
'classif_res': forms.Select(attrs={'class':'form-control'}),
'amt_granted': forms.TextInput(attrs={'class':'form-control'}),
'date_started': forms.DateInput(attrs={'placeholder':'YYYY-MM-DD','class':'form-control'}),
'res_status': forms.RadioSelect(attrs={'class':'form-check-input'}),
'date_completed': forms.DateInput(attrs={'placeholder':'YYYY-MM-DD','class':'form-control'}),
'res_SF': forms.CheckboxSelectMultiple(attrs={'class':'form-check-input'}),
'res_pubstat': forms.RadioSelect(attrs={'class':'form-check-input'}),
'res_JN': forms.TextInput(attrs={'class':'form-control'}),
'res_JV': forms.TextInput(attrs={'class':'form-control'}),
'date_pub': forms.DateInput(attrs={'placeholder':'YYYY-MM-DD','class':'form-control'}),
'res_iprstat':forms.RadioSelect(attrs={'class':'form-check-input'}),
'apptype':forms.RadioSelect(attrs={'class':'form-check-input'}),
'date_appl':forms.DateInput(attrs={'placeholder':'YYYY-MM-DD','class':'form-control'}),
'date_pprv':forms.DateInput(attrs={'placeholder':'YYYY-MM-DD','class':'form-control'}),
'app_pending': forms.RadioSelect(attrs={'class':'form-check-input'}),
'res_abs': forms.Textarea(attrs={'class':'form-control'})
}
(views.py):
from django.shortcuts import render
from django.http import HttpResponse
from .forms import ResearchForm
from .models import List_of_Res
def RIS_Home(request):
return render(request,'RIS/RIS_Home.html')
def Add_Res(request):
if request.method=='POST':
form = ResearchForm(request.POST)
if form.is_valid():
resAdd=form.save(commit=False)
resAdd.save()
else:
form = ResearchForm()
args = {'form':form}
return render(request,'RIS/RIS_Add-Edit.html',args)
(models.py)
from django.db import models
class List_of_Res(models.Model):
Yes_no_Choices = (('YES','YES'),('NO','NO'))
Stat_choices = (("COMPLETED","Completed"),("ON_GOING","On-Going"))
Campus_choices = (
("APARRI","Aparri"),
("LASAM","Lasam"),
("LALLO","Lal-lo"),
("SANCHEZ_MIRA","Sanchez Mira"),
("CARIG","Carig"),
("ANDREWS","Andrews"),
("PIAT","Piat")
)
Category_choices = (
("BASIC","Basic"),
("APPLIED","Applied"),
("PILOT_TESTING","Pilot Testing"),
("TECHNOLOGY_PROMOTION_COMMERCIALIZATION","Technology Promotion / Commercialization")
)
Classification_choices = (
("AGRICULTURE","Agriculture"),
("BIOTECHNOLOGY","Biotechnology"),
("ICT","ICT"),
("HEALTH_PRODUCTS","Health Products"),
("ALTERNATIVE_ENERGY","Alternative Energy"),
("CLIMATE_CHANGE","Climate Change"),
("ENVIRONMENT","Environment"),
("SOCIO_ECONOMIC","Socio-economic"),
("NATURAL_PRODUCTS","Natural Products"),
("OTHER","Other")
)
Source_fund_choices = (
("CSU","CSU"),
("CHED","CHED"),
("DA_BAR","DA-BAR"),
("DOST","DOST"),
("PCCARRD","PCCARRD"),
("PCIERD","PCIERD"),
("PCHRD","PCHRD"),
("DA","DA"),
("OTHER","Other")
)
IPR_Type_choices = (
("PATENT","Patent"),
("UTILITY_MODEL","Utility Model"),
("TRADEMARK_TRADENAME","Trademark/Tradename"),
("COPYRIGHT","Copyright"),
("OTHER","Other")
)
prog_title = models.CharField(max_length=1000)
proj_title = models.CharField(max_length=1000)
stud_title = models.CharField(max_length=1000)
prog_lead = models.CharField(max_length=300)
stud_lead = models.CharField(max_length=300)
co_res = models.TextField()
res_site = models.TextField()
campus = models.CharField(max_length=50,choices=Campus_choices,default='ANDREWS')
category_res = models.CharField(max_length=50,choices=Category_choices,default='BASIC')
classif_res = models.CharField(max_length=50,choices=Classification_choices,default='ICT')
amt_granted = models.TextField()
date_started = models.TextField()
res_status = models.CharField(max_length=10, choices=Stat_choices, default='COMPLETED')
date_completed = models.TextField()
res_SF = models.TextField(choices=Source_fund_choices,default='CSU')
res_pubstat = models.CharField(max_length=5,choices=Yes_no_Choices, default='YES')
res_JN = models.TextField()
res_JV = models.CharField(max_length=100)
date_pub = models.TextField()
res_iprstat = models.CharField(max_length=10, choices=Yes_no_Choices, default='YES')
apptype = models.CharField(max_length=100,choices=IPR_Type_choices,default='PATENT')
date_appl = models.TextField()
date_pprv = models.TextField()
app_pending = models.CharField(max_length=10, choices=Yes_no_Choices, default='YES')
res_abs = models.CharField(max_length=1000)
end this is the html template
{% extends 'RIS/RIS_Home.html' %}
{% block body %}
<div class="container">
<form method="post">
<div>
{% csrf_token %}
<div>
<div class="row"><div class="boxed_content">Title of Research</div></div>
<br>
<div class="row">
<label class="label_style_AEform">Program Title</label>
<br>
{{ form.prog_title }}
</div>
<div class="row">
<label class="label_style_AEform">Project Title</label>
<br>
{{ form.proj_title }}
</div>
<div class="row">
<label class="label_style_AEform">Study Title</label>
<br>
{{ form.stud_title }}
</div>
</div>
<br>
<div>
<br>
<div class="row"><div class="boxed_content">Researcher/s</div></div>
<br>
<div class="row">
<div class="col">
<div class="row">
<label class="label_style_AEform">Program Leader</label>
<br>
{{ form.prog_lead }}
</div>
<br><br><br>
<div class="row">
<label class="label_style_AEform">Study Leader</label>
<br>
{{ form.stud_lead }}
</div>
</div>
<div class="col">
<label class="label_style_AEform">Co-Researcher/s</label>
<br>
{{ form.co_res }}
</div>
</div>
</div>
<div>
<br>
<div class="row"><div class="boxed_content">Site / Location of study</div></div>
<br>
<div class="row">
{{ form.res_site }}
</div>
</div>
<div>
<br>
<div class="row"><div class="boxed_content">Category of Research</div></div>
{% for rdo in form.category_res %}
<div class="form-check form-check-inline">
{{ rdo }}
</div>
{% endfor %}
</div>
<br>
<div>
<div class="row">
<div class="col">
<div class="row"><div class="boxed_content">Classification of Research<br>
{{ form.classif_res }}
</div></div>
</div>
<div class="col">
<div class="row"><div class="boxed_content">Campus<br>
{{ form.campus }}
</div></div>
</div>
</div>
</div>
<br>
<div>
<div class="row">
<div class="col">
<div class="row"><div class="boxed_content">Source of Fund</div></div>
{% for chk in form.res_SF %}
<div class="form-check form-check-inline">
{{ chk }}
</div>
{% endfor %}
</div>
<div>
<div class="col">
<div class="row"><div class="boxed_content">Amount Granted<br>{{ form.amt_granted }}</div></div>
</div>
</div>
</div>
</div>
<br>
<div>
<div class="row">
<div class="col">
<div class="row"><div class="boxed_content">Status of Research</div></div>
{% for rdo in form.res_status %}
<div class="form-check form-check-inline">
{{ rdo }}
</div>
{% endfor %}
</div>
<div class="col">
<div class="row"><div class="boxed_content">Date Started<br>
<div class="form-check form-check-inline">
{{ form.date_started }}
</div>
</div></div>
</div>
<div class="col">
<div class="row"><div class="boxed_content">Date Completed<br>
<div class="form-check form-check-inline">
{{ form.date_completed }}
</div>
</div></div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="boxed_content">Is the research published?
{% for rdo in form.res_pubstat %}
<div class="form-check form-check-inline">
{{ rdo }}
</div>
{% endfor %}
</div>
<br>
<div class="row">
<div class="col">
<label class="label_style_AEform">If Yes,</label>
</div>
<div class="col">
<label class="label_style_AEform">Name of Journal</label>
{{ form.res_JN }}
</div>
<div class="col">
<label class="label_style_AEform">Volume</label>
{{ form.res_JV }}
</div>
<div class="col">
<label class="label_style_AEform">Date Published</label>
<div class="form-check form-check-inline">
{{ form.date_pub }}
</div>
</div>
</div>
</div>
<br>
<div class="row">
<div class="boxed_content">Does the research have IPR application?
{% for rdo in form.res_iprstat %}
<div class="form-check form-check-inline">
{{ rdo }}
</div>
{% endfor %}
</div>
<br>
<div class="row">
<div class="col">
<label class="label_style_AEform">If Yes, Application Type: </label>
{% for rdo in form.apptype %}
<div class="form-check form-check-inline">
{{ rdo }}
</div>
{% endfor %}
</div>
</div>
<div class="row">
<div class="col">
<label class="label_style_AEform">Date of Application</label>
<div class="form-check form-check-inline">
{{ form.date_appl }}
</div>
</div>
<div class="col">
<label class="label_style_AEform">Date of Approval of application</label>
<div class="form-check form-check-inline">
{{ form.date_pprv }}
</div>
</div>
<br>
<div class="col">
<label class="label_style_AEform">Is the application Pending? </label>
{% for rdo in form.app_pending %}
<div class="form-check">
{{ rdo }}
</div>
{% endfor %}
</div>
</div>
</div>
<div class="row">
<div class="boxed_content">Abstract of the study</div>
<br>
{{ form.res_abs }}
</div>
</div>
<div class="row"><button type="submit" class="btn btn-primary mb-2">SAVE</button></div>
</form>
</div>
{% endblock %}
You should use MultipleChoiceField in your forms as a widget.
'res_SF': forms.MultipleChoiceField(attrs={'class':'form-check-input'}),

Categories