I am developing a inventory management and I have to subtract the Quantity from 2 different forms data and display the available quantity.
Below is my views.py
def my_form2(request):
if request.method == "POST":
form2 = MyForm2(request.POST)
if form2.is_valid():
form2.save()
return HttpResponse('Submitted Successfully')
else:
form2 = MyForm2()
return render(request, "authentication/Incoming_QC.html", {'form2': form2})
def View_Incoming_QC(request):
Incoming_QC_list = Incoming_QC.objects.all()
return render(request, 'authentication/View_Incoming_QC.html',
{'Incoming_QC_list': Incoming_QC_list})
def my_form3(request):
if request.method == "POST":
form3 = MyForm3(request.POST)
if form3.is_valid():
form3.save()
return HttpResponse('Submitted successfully')
# return redirect('/home_page/')
else:
form3 = MyForm3()
return render(request, "authentication/Manufacturing.html", {'form3': form3})
def View_Manufacturing(request):
Manufacturing_list = Manufacturing.objects.all()
return render(request, 'authentication/View_Manufacturing.html',
{'Manufacturing_list': Manufacturing_list})
def my_form5(request):
if request.method == "POST":
form5 = MyForm5(request.POST)
if form5.is_valid():
form5.save()
return HttpResponse('Submitted successfully')
# return redirect('/home_page/')
else:
form5 = MyForm5()
return render(request, "authentication/Material.html", {'form5': form5})
def View_Material(request):
Material_list = Material.objects.all()
return render(request, 'authentication/View_Material.html',
{'Material_list': Material_list})
Below is the models.py
class Incoming_QC(models.Model):
alphanumeric = RegexValidator(r'^[\s0-9a-zA-Z\.-_]*$', 'Only alphanumeric characters are allowed.')
Manufacturing_PN = models.CharField(max_length=200, validators=[alphanumeric])
Quantity = models.IntegerField()
class Manufacturing(models.Model):
alphanumeric = RegexValidator(r'^[\s0-9a-zA-Z\.-_]*$', 'Only alphanumeric characters are allowed.')
Manufacturing_PN = models.CharField(max_length=200, validators=[alphanumeric])
Completed_Quantity = models.IntegerField(blank=True, default='')
class Material(models.Model):
alphanumeric = RegexValidator(r'^[\s0-9a-zA-Z\.-_]*$', 'Only alphanumeric characters are allowed.')
Manufacturing_PN = models.CharField(max_length=200, validators=[alphanumeric])
Quantity = models.IntegerField()
.html file to view the data
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
table, th, td {
border:1px solid black;
}
body {
margin-bottom: 100px;
background-color: lightgrey;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
{% csrf_token %}
{% load static %}
<div class="topnav">
Home
Material Details
View Material Details
</div>
<div style="padding-left:16px">
</div>
<h1>
<center>
Material Details
</center>
</h1>
<table style="width:100%">
<thead>
<tr>
<th>Manufacturing_PN</th>
<th>Quantity</th>
</tr>
</thead>
<tbody>
<tr>
{% for Material in Material_list %}
<strong> {{ Material }}</strong>
<td> {{Material.Manufacturing_PN }} </td>
<td> {{Material.Quantity}} </td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
</html>
SO here whenever the user submit the incoming QC and Manufacturing forms. The Quantity entered by the user in both the form or single form I want to subtract the Quantity of the Material data.
Note: The Quantity should be subtracted based on the manufacturing_PN.
It should look like below logic:
if Material.manufacturing_PN == Manufacturing.manufacturing_PN || Material.manufacturing_PN == Incoming_QC.manufacturing_PN
Material.manufacturing_PN = Material.manufacturing_PN - Incoming_QC.manufacturing_PN - Manufacturing.manufacturing_PN
It would be very helpful if someone help me out in this. Thanks in advance
Related
I am trying to build a inventory management project facing some difficulty, Looking for a solution.
I have created a 2 form in django model and when I try to load form2 only form1 is loading for all the condition.
I have tried to comment form1 and load only form2 with that I got the expected result but when I try to add run with both the forms I am facing the issue.
Additional to this in django admin panel I am getting I am getting both the forms as expected.
Any kind of help will be appreciated.
Views.py
from .models import Inventory_Details, Incoming_QC
from .forms import MyForm, Incoming_QC_form
def my_form(request):
if request.method == "POST":
form = MyForm(request.POST)
if form.is_valid():
form.save()
return HttpResponse('Submitted successfully')
#return redirect('/home_page/')
else:
form = MyForm()
return render(request, "authentication/Inventory_details.html", {'form': form})
def View_Inventory(request):
Inventory_list = Inventory_Details.objects.all()
return render(request,'authentication/View_Inventory.html',
{'Inventory_list': Inventory_list})
def Incoming_qc_form(request):
if request.method == "POST":
QC_form = Incoming_QC_form(request.POST)
if QC_form.is_valid():
QC_form.save()
return HttpResponse('Submitted successfully')
#return redirect('/home_page/')
else:
QC_form = Incoming_QC_form()
return render(request, "authentication/Incoming_QC.html", {'QC_form': QC_form})
def View_Incoming_QC(request):
Incoming_QC_list = Incoming_QC.objects.all()
return render(request,'authentication/View_Incoming_QC.html',
{'Incoming_QC_list': Incoming_QC_list})
urls.py
url(r'form', views.my_form, name='form'),
path('View_Inventory', views.View_Inventory, name="View_Inventory"),
url(r'QC_form', views.Incoming_qc_form, name='QC_form'),
path('View_Incoming_QC', views.View_Incoming_QC, name="View_Incoming_QC")
html
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin-bottom: 100px;
background-color: lightgrey;
font-family: Arial, Helvetica, sans-serif;
}
.topnav {
overflow: hidden;
background-color: #333;
}
.topnav a {
float: left;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
font-size: 17px;
}
.topnav a:hover {
background-color: #ddd;
color: black;
}
.topnav a.active {
background-color: #04AA6D;
color: white;
}
</style>
</head>
<body>
{% csrf_token %}
{% load static %}
<div class="topnav">
Home
Incoming Quality Check
Inventory Store Management
Inventory Details
Incoming QC details
</div>
<div style="padding-left:16px">
</div>
<div class="container">
<form method="POST">
<fieldset style="margin-block:15px">
<legend>Incoming_QC</legend>
{% csrf_token %}
{{ QC_form.as_p }}
<button type="submit" class="btn btn-primary">Submit</button>
</fieldset>
</form>
</div>
</body>
</html>
forms.py
from django import forms
from .models import Inventory_Details, Incoming_QC
class MyForm(forms.ModelForm):
class Meta:
model = Inventory_Details
fields = ["Invoice_number",
"AWB",
"Received_from",
"Description",
"Quantity",
"Received_date",
"Received_by",
"Assigned_To",
"Manufacturing_PN",]
labels = {'Invoice_number': "Invoice_number",
'AWB':"AWB",
'Received_from':"Received_from",
'Description':"Description",
'Quantity':"Quantity",
'Received_date':"Received_date",
'Received_by':"Received_by",
'Assigned_To':"Assigned_To",
'Manufacturing_PN':"Manufacturing_PN",
'Manufacturer':"Manufacturer",
}
class Incoming_QC_form(forms.ModelForm):
class Meta:
model = Incoming_QC
fields = ["Manufacturer",
"Location",
"Inspected_By",
"Conducted_On",
"Supplier_name",
"Supplier_address",
"PO_number",
"Material_name",
"Part_number",
"Quantity",
]
labels = {'Manufacturer': "Manufacturer",
'Location': "Location",
'Inspected_By': "Inspected_By",
'Conducted_On': "Conducted_On",
'Supplier_name': "Supplier_name",
'Supplier_address': "Supplier_address",
'PO_number': "PO_number",
'Material_name': "Material_name",
'Part_number': "Part_number",
'Quantity': "Quantity",
}
Thanks in advance
Instead of this:
Incoming Quality Check
Inventory Store Management
Try this:
Incoming Quality Check
Inventory Store Management
I think the problem is in view.
Simply try this:
def Incoming_qc_form(request):
if request.method == "POST":
qcform = Incoming_QC_form(request.POST)
if qcform.is_valid():
qcform.save()
return HttpResponse('Submitted successfully')
#return redirect('/home_page/')
else:
qcform = Incoming_QC_form()
return render(request, "authentication/Incoming_QC.html", {'qcform': qcform})
And in template:
{{qcform}}
im trying to create a django page for update a dta inside database, i made this before in other projects and aways worked, but in my project it returns this error: django.urls.exceptions.NoReverseMatch: Reverse for 'update' with arguments '('',)' not found. 1 pattern(s) tried: ['update/(?P[0-9]+)$']
i reviewed my code a thousand times and i can't see nothing wrong, even if comparing with the other projects.
Obs.: please ignore the css part of my template, i'm not used to write the css inside the html, but as it's just a test i don't create a external file.
urls.py:
from django.urls import path
import tables1.views as vw
urlpatterns = [
path('admin/', admin.site.urls, name = 'admin'),
path('mytables/', vw.mytables, name = 'mytables'),
path('',vw.home),
path('table/<int:pk>',vw.table, name = 'tableurl'),
path('newtable/',vw.newtable,name = 'newtable'),
path('update/<int:pk>',vw.update,name = 'update'),
path('delete/<int:pk>',vw.delete,name = 'delete'),
path('new/',vw.new, name = 'newurl')
]
models.py:
class Table(models.Model):
idd = models.AutoField(primary_key=True, default=None)
name = models.CharField(max_length=100)
date = models.DateField(auto_now_add=True)
time = models.TimeField(auto_now_add=True)
class Meta:
verbose_name_plural = 'Tables'
def __str__(self):
return self.name
class Transacao(models.Model):
# Forein key defined here
date = models.DateTimeField(auto_now_add=True)
desc = models.CharField(max_length=200)
value = models.DecimalField(max_digits=7, decimal_places=2)
obs = models.TextField(null=True, blank=True)
tableid = models.CharField(max_length=3)
class Meta:
verbose_name_plural = 'Transacoes'
def __str__(self):
return self.desc
views.py:
from .models import Table
from .models import Transacao
from .forms import TableForm
from .forms import TransacaoForm
def home(request):
now = {}
return render(request,'tables1/home.html',now)
def mytables(request):
data = {}
data['tables'] = Table.objects.all()
return render(request, 'tables1/mytables.html', data)
def update(request,pk):
transacao = Transacao.objects.get(pk = pk)
form = TransacaoForm(request.POST or None, instance=transacao)
if form.is_valid():
form.save()
return render(request,'tables1/new.html',{'form':form})
def new(request):
form = TransacaoForm(request.POST or None)
if form.is_valid():
form.save()
return render(request,'contas/form.html',{'form':form})
def delete(request,pk):
transacao = Transacao.objects.get(pk = pk)
transacao.delete()
return redirect('lists')
def table(request,pk):
form = TransacaoForm(request.POST or None)
data = Table.objects.get(idd = pk)
lists = Transacao.objects.filter(tableid = pk)
if request.method == 'POST':
if form.is_valid():
formdesc = form.cleaned_data['desc']
formvalue = form.cleaned_data['value']
transaction_instance = Transacao.objects.create(desc = formdesc,value = formvalue,tableid = pk)
return render(request,'tables1/table.html',{'data':data, 'form':form, 'lists':lists})
def newtable(request):
form = TableForm(request.POST or None)
if form.is_valid():
form.save()
return redirect('mytables')
return render(request,'tables1/newtable.html',{'form':form})
table.html:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {font-family: Arial, Helvetica, sans-serif;}
* {box-sizing: border-box;}
/* Button used to open the contact form - fixed at the bottom of the page */
.open-button {
background-color: #555;
color: white;
padding: 16px 20px;
border: none;
cursor: pointer;
opacity: 0.8;
}
/* The popup form - hidden by default */
.form-popup {
display: none;
bottom: 0;
right-margin: 10px;
right: 15px;
border: 3px solid #f1f1f1;
z-index: 9;
}
/* Add styles to the form container */
.form-container {
max-width: 300px;
padding: 10px;
background-color: white;
}
/* Full-width input fields */
.form-container input[type=text], .form-container input[type=password] {
width: 100%;
padding: 15px;
margin: 5px 0 22px 0;
border: none;
background: #f1f1f1;
}
/* When the inputs get focus, do something */
.form-container input[type=text]:focus, .form-container input[type=password]:focus {
background-color: #ddd;
outline: none;
}
/* Set a style for the submit/login button */
.form-container .btn {
background-color: #4CAF50;
color: white;
padding: 16px 20px;
border: none;
cursor: pointer;
width: 100%;
margin-bottom:10px;
opacity: 0.8;
}
/* Add some hover effects to buttons */
.form-container .btn:hover, .open-button:hover {
opacity: 1;
}
</style>
</head>
<body>
<h1>{{data}}</h1>
<table id = tabela>
<tr>
<th>Item</th>
<th>Data e Hora</th>
<th>Valor</th>
</tr>
{% for list in lists %}
<tr>
<td>{{list.desc}}</td><td>{{list.date}}</td>
<td>{{list.value}}</td><td>{{list.categ}}</td>
<td><form action="{% url 'update' transacao.id %}">
<button type="submit"><b>Editar</b></button>
</form></td>
<td><form action="{% url 'delete' transacao.id %}">
<button type="submit"><b>Excluir</b></button>
</form></td>
</tr>
{%endfor%}
</table>
<button class="open-button" onclick="{% url newurl %}">Nova Transação</button>
<form method="post" class="form-container">
{% csrf_token %}
{{form.as_p}}
<button type="submit" class="btn" onclick="location.reload()">Login</button>
<button type="button" class="btn cancel" onclick="closeForm()">Close</button>
</form>
</body>
</html>
transacao is not a variable in your template, you use list as a variable for a Transacao object, therefore you should use {% url 'update' list.id %} and {% url 'delete' list.id %}:
{% for list in lists %}
<tr>
<td>{{ list.desc }}</td><td>{{ list.date }}</td>
<td>{{ list.value }}</td><td>{{ list.categ }}</td>
<td><form action="{% url 'update' list.id %}">
<button type="submit"><b>Editar</b></button>
</form></td>
<td><form action="{% url 'delete' list.id %}">
<button type="submit"><b>Excluir</b></button>
</form></td>
</tr>
{%endfor%}
That being said, since your lists is not a collection of lists - it is a QuerySet of Transacaos - it might be better to rename lists to transacaos and use transacao as "enumerator".
Bit of a rudimentary Django question. I would like to have a form that asks a user for their name and message and then sends this information to an email (more like a contact form).
This is what I have in my views.py:
def assignmentSubs(request):
if request.method == 'GET':
form = AssignmentSubs()
else:
form = AssignmentSubs(request.POST)
if form.is_valid():
subject = 'Assignment submission: {}'.format(form.cleaned_data['assignment'])
from_email = 'x2x#gmail.com'
message = 'Hi, Please note that {} has submitted an assignment for the {} section. We will reach out to you with more detail regarding this submission'.format(form.cleaned_data['link'],form.cleaned_data['assignment'])
send_mail(subject, message, from_email,['xxx#gmail.com','xxx2.des8#gmail.com'], fail_silently=False)
return render(request, 'form.html', {'form': form})
forms.py
class AssignmentSubs(forms.ModelForm):
assignment = forms.CharField(max_length=100, widget=forms.TextInput(attrs={'class': 'form-field', 'id':'assignmentname'}), required=True)
link = forms.CharField(required=True, max_length=100, widget=forms.TextInput(attrs={'class': 'form-field'}))
and the html with the form
<form method="post" action="/" id="form" class="validate">
{% csrf_token %}
<div class="form-field">
{{form.assignment}}
</div>
<div class="form-field">
{{form.link}}
</div>
<div class="form-field">
<label for=""></label>
<input type="submit" value="Submit Assignment" />
</div>
</form>
and the css:
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
#form {
max-width: 700px;
padding: 2rem;
box-sizing: border-box;
}
.form-field {
display: flex;
margin: 0 0 1rem 0;
}
label, input {
width: 70%;
padding: 0.5rem;
box-sizing: border-box;
justify-content: space-between;
font-size: 1.1rem;
}
label {
text-align: right;
width: 30%;
}
input {
border: 2px solid #aaa;
border-radius: 2px;
}
</style>
and my urls.py
This is a two fold problem, I cannot see any of the fields from my form and cannot actually send emails through the form
urlpatterns = [
path('', home, name='home'),
path('about', about, name='about'),
path('courses', courses, name='courses'),
path('notyet', notyet, name='notyet'),
path('faqs',faqs, name='faqs'),
path('students', students, name='students'),
...
Here is the structure of my project
templates
>classroom (folder)
>students
htmlfiles
>teachers
htmlfiles
home.html
>views
students.py (this is the views.py I am referring to)
I've made some changes to your views. Your Form seems fine just make sure the action attribute of your form points to the correct view.
Note: make sure your template i.e form.html is present inside templates directory of your current Django app
from django.shortcuts import render, redirect
def assignmentSubs(request):
if request.method == "GET":
form = AssignmentSubs()
return render(request, "form.html", {"form": form})
else:
form = AssignmentSubs(request.POST)
if form.is_valid():
subject = "Assignment submission: {}".format(
form.cleaned_data["assignment"]
)
from_email = "x2x#gmail.com"
message = "Hi, Please note that {} has submitted an assignment for the {} section. We will reach out to you with more detail regarding this submission".format(
form.cleaned_data["link"], form.cleaned_data["assignment"]
)
send_mail(
subject,
message,
from_email,
["xxx#gmail.com", "xxx2.des8#gmail.com"],
fail_silently=False,
)
# use redirect in any of the following way
# return redirect("some-view-name", foo="bar")
return redirect("/same/valid/url")
HTML file (+Flask+Bootstrap)
{% extends "bootstrap/base.html" %}
{% block content %}
<html>
<head>
<style>
table, th, td {
background: #f5f5f5;
border-collapse: separate;
box-shadow: inset 0 1px 0 #fff;
font-size: 12px;
line-height: 24px;
margin: 30px auto;
text-align: left;
width: 800px;
}
.center {
text-align: center;
margin: auto;
width: 80%;
border: 3px solid rgba(0, 0, 0, 0);
padding: 20px;
}
.footer {
position: absolute;
right: 0;
bottom: 0;
left: 0;
padding: 1rem;
background-color: #efefef00;
text-align: center;
}
</style>
</head>
<body>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<ul class="nav navbar-nav">
<a class="navbar-brand"> TMS </a>
<li>Routing</li>
</ul>
</div>
</nav>
<table style="width:auto" align="center">
<tr>
<th>
<p>Select the route sheet:</p>
<div class='center'>
<form ip="upload-form" action="{{ url_for('routing') }}" method="POST"
enctype="multipart/form-data">
<input type="file" name="file" accept="/" multiple>
<input type="submit" action="submit" value="send">
</div>
</th>
</tr>
</table>
{% if ifHTMLConditional %}
<form method='POST' action="{{ url_for('routing') }}">
<table>
<tr>
<th>Name</th>
<th>Meters</th>
</tr>
{% for i in returnFromObjectClassRoute %}
<tr>
<td>
<input type="checkbox" name="vehicle" value= {{ i[1] }}>
{{ i[1] }}
</input>
</td>
<td>
{{ i[2] }}
</td>
</tr>
{% endfor %}
</table>
<input type="submit" value = {{ test.test }}>
{% endif %}
</form>
</body>
</html>
{% endblock %}
How could I use this for loop to create the number of checkboxes but with returns for using them in next functionalities.
The goal of the program is to create a Short Route. With the checkbox I want to let the user to select where is the startPoint for the algorithm
Python Code
#app.route('/routing', methods=['GET', 'POST'])
def routing():
test = Reference()
print(test.test.data)
if test == True:
return redirect('/home')
else:
if request.method == 'POST':
directory = os.path.join(APP_ROOT)
ifHTMLConditional = False
if not os.path.isdir(directory):
os.mkdir(directory)
for file in request.files.getlist("file"):
filename = file.filename
destination = "/".join([directory, filename])
if file.filename != '':
file.save(destination)
objectFromClassRoute = Route(filename, 'totalDistances_AB_BA_12012018.csv')
returnFromObjectClassRoute = objectFromClassRoute.routing1()
ifHTMLConditional = True
else:
returnFromObjectClassRoute = []
ifHTMLConditional = False
return redirect ('/home')
return render_template('routing.html', test=test, returnFromObjectClassRoute=returnFromObjectClassRoute, ifHTMLConditional=ifHTMLConditional)
return render_template('routing.html')
returnFromObjectClassRoute returns a list as a value.
Python code
An example for what I was looking for:
from flask import Flask, render_template, request
app = Flask(__name__)
app.config['SECRET_KEY'] = 'ThisIsSecret'
class Reference():
def testList(self):
testList = ['ABC', 'DEF', 'GHI']
return testList
#app.route('/home', methods=['GET', 'POST'])
def home():
test1 = Reference()
test = test1.testList()
print(test1.testList())
if request.method == "POST":
selected_contacts = request.form.getlist("test")
return render_template('checkBoxTest.html', test=test)
if __name__ == '__main__':
app.run(debug=True)
Html + Jinja2 code
<html>
<head>
</head>
<body>
<form method='POST' action="{{ url_for('home') }}">
{{ test.csrf_token }}
{% for i in test %}
<input type="checkbox" name="test" value="{{i}}">
<label>{{i}}</label>
{% endfor %}
<input type="submit" action="submit">
</form>
</body>
</html>
It returns all the check list you had activate before submitting and return a list of the values where you can used them as you want
I don't know what is the problem and I've been stuck here for hours. There maybe duplicate questions but none of them could get me out of this.
I am using an if condition in the inner loop to check if the attribute of inner is equal to the outer loop but if condition is never true even the data is same.
I've printed the data individually, both attributes print the data mean data is correct. But when I use if condition it goes to else
Data
Here's the data I'm working with:
activityy.activity_name = [Table Tennis,Swimming Pool, Football ]
slot.activity = [Table Tennis,Table Tennis,Table Tennis,Table Tennis,Swimming Pool, Football]
activities.html
{% for activityy in all_activities%}
<div style="margin-left: 450px; padding: 15px; border-radius: 5px; background-color: #dfdfdf;height: 150px; width: 800px; margin-top: 20px; text-align: center">
{% for slot in all_slots %}
{% if slot.activity == activityy.activity_name %}
<div style="background-color: #3a589a; padding: 15px; width: 120px; height: 120px; float: left; border-radius: 5px;">
<span style="color: #f1f1f1; font-size: 20px;"> {{ activityy.activity_name}}</span><br>
</div>
{% else %}
<div style="background-color: #589a; padding: 15px; width: 120px; height: 120px; float: left; border-radius: 5px;">
<span style="color: #f1f1f1; font-size: 20px;"> {{ slot.activity}}</span><br>
</div>
{% endif %}
{% endfor %}
</div>
{% endfor %}
Views.py
def activities(request):
if request.user.is_authenticated:
template = loader.get_template('sklc/activities.html')
slots = []
now = datetime.datetime.now()
datee = now.strftime("%Y-%m-%d")
if request.method == 'POST':
dat = request.POST['date']
if dat:
datee = dat
print("dateesss: " , datee)
activitiess = Activities.objects.all();
for activityy in activitiess:
slot = ActivitySlots.objects.filter(dates=datee).filter(activity__activity_name=activityy.activity_name)
for slott in slot:
slots.append(slott)
context = {
'all_activities': activitiess,
'all_slots': slots
}
return HttpResponse(template.render(context, request))
else:
messages.error(request, "Please Login First")
return redirect("/login")
models.py
class Activities(models.Model):
activity_name = models.CharField(max_length=50)
def __str__(self):
return self.activity_name
class ActivitySlots(models.Model):
dates = models.DateField()
available = models.BooleanField()
activity = models.ForeignKey(Activities)
time = models.CharField(max_length=50)
def __str__(self):
return self.time
I solved it by using
{% if slot.activity == activityy %}
Butt still don't know why it was not working with activityy.activity_name because activityy and activityy_activity_name are printing the same thing.