Django Unable to pass a variable name in the next template - django

Hi I am facing a problem in my project .
In the Patient list, if a Click the Notes row present in the Add notes column. The new template load where it will list the recent notes for the patients... and also it allows me add patient notes by selecting the patient ( i am passing the objects of patients through forms )
My problem ..
How to add notes to the specified patient only. ( i.e. by not passing through forms) and also filtering to display the specfic Patient notes only.
Code
Model:
class Notes(models.Model):
doctorId = models.PositiveIntegerField(null=True)
patientName = models.CharField(max_length=40, null=True)
report = models.TextField(max_length=500)
NoteDate = models.DateTimeField(default=timezone.now)
#def __str__(self):
# return self.patientName+" "+self.report
#property
def get_id(self):
return self.id
View
#login_required(login_url='doctorlogin')
#user_passes_test(is_doctor)
def doctor_add_notes_view(request):
appointmentForm=forms.PatientNotesForm()
notes = models.Notes.objects.all().order_by('-NoteDate')
mydict={'appointmentForm':appointmentForm,'notes':notes}
if request.method=='POST':
appointmentForm=forms.PatientNotesForm(request.POST)
if appointmentForm.is_valid():
appointment=appointmentForm.save(commit=False)
appointment.doctorId =request.user.id #request.POST.get('doctorId')
doctors = models.Appointment.objects.all().filter(AppointmentStatus=True, status=True)
appointment.patientName = models.User.objects.get(id=request.POST.get('patientId')).first_name
now = datetime.now()
print("Current date and time : ")
print(now.strftime("%Y-%m-%d %H:%M:%S"))
appointment.NoteDate = now
print('doctors', doctors)
appointment.save()
return HttpResponseRedirect('doctor-view-patient')
else:
print(appointmentForm.errors)
return render(request, 'hospital/doctor_view_patient.html',{'alert_flag': True})
return render(request,'hospital/doctor_add_notes.html',context=mydict)
def doctor_view_patient_view(request):
appointments1 = models.Appointment.objects.all().filter(AppointmentStatus=False, status=True,doctorId=request.user.id)
print('appointments are ', appointments1)
patientid = []
for a in appointments1:
patientid.append(a.patientId)
print('patientid', patientid)
patients = models.Patient.objects.all().filter(PatientStatus=True, status=True, user_id__in=patientid)
print('patients', patients)
print(request.user.id)
doctor=models.Doctor.objects.get(user_id=request.user.id) #for profile picture of doctor in sidebar
print('doctor', doctor)
notes = models.Notes.objects.all().order_by('-NoteDate')
#print(notes)
return render(request,'hospital/doctor_view_patient.html',{'patients':patients,'doctor':doctor,'notes':notes})
Forms
class PatientNotesForm(forms.ModelForm):
patientId=forms.ModelChoiceField(queryset=models.Patient.objects.all().filter(status=True),empty_label="Patient Name and Symptoms", to_field_name="user_id")
class Meta:
model=models.Notes
fields=['report']
**doctor_view_patient.html
{% extends 'hospital/doctor_base.html' %}
{% block content %}
{%load static%}
<head>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<style media="screen">
a:link {
text-decoration: none;
}
h6 {
text-align: center;
}
.row {
margin: 100px;
}
</style>
</head>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
<h6 class="panel-title">Your Total Patient List</h6>
</div>
<table class="table table-hover" id="dev-table">
<thead>
<tr>
<th>Name</th>
<th>Profile Picture</th>
<th>Symptoms</th>
<th>Mobile</th>
<th>Address</th>
<th>Add Notes</th>
</tr>
</thead>
{{Notes.get_id}}
{% for p in patients %}
<tr>
<td> {{p.get_name}}</td>
<td> <img src="{% static p.profile_pic.url %}" alt="Profile Pic" height="40px" width="40px" /></td>
<td>{{p.symptoms}}</td>
<td>{{p.mobile}}</td>
<td>{{p.address}}</td>
<td><a class="btn btn-primary btn-xs" href="{% url 'doctor-add-notes' %}">Notes</a></td>
</tr>
{% endfor %}
</table>
</div>
</div>
{% endblock content %}
doctor_add_notes.html
{% extends 'hospital/doctor_base.html' %}
{% load widget_tweaks %}
{% block content %}
<head>
<style media="screen">
a:link {
text-decoration: none;
}
.note {
text-align: center;
height: 80px;
background: -webkit-linear-gradient(left, #0072ff, #8811c5);
color: #fff;
font-weight: bold;
line-height: 80px;
}
.form-content {
padding: 5%;
border: 1px solid #ced4da;
margin-bottom: 2%;
}
.form-control {
border-radius: 1.5rem;
}
.btnSubmit {
border: none;
border-radius: 1.5rem;
padding: 1%;
width: 20%;
cursor: pointer;
background: #0062cc;
color: #fff;
}
.menu {
top: 50px;
}
</style>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<br><br>
<div class="container register-form">
<div class="form">
<div class="note">
<p>Recent patient Notes</p>
</div>
</div>
<table class="table table-hover" id="dev-table">
<thead>
<tr>
<th>Name</th>
<th>Notes</th>
<th>Date</th>
</tr>
</thead>
{{Notes.get_id}}
{% for a in notes %}
<tr>
<td>{{a.patientName}}</td>
<td>{{a.report}}</td>
<td>{{a.NoteDate}}</td>
</tr>
{% endfor %}
</table>
</div>
</div>
</div>
<form method="post">
{% csrf_token %}
<div class="container register-form">
<div class="form">
<div class="note">
<p>Add New Notes</p>
</div>
<div class="form-content">
<div class="row">
<div class="col-md-12">
<div class="form-group">
{% render_field appointmentForm.report class="form-control" placeholder="Description" %}
</div>
<div class="form-group">
{% render_field appointmentForm.patientId class="form-control" placeholder="Patient" %}
</div>
<div class="form-group">
{% render_field appointmentForm.NoteDate class="form-control" placeholder="Date" %}
</div>
</div>
</div>
<button type="submit" class="btnSubmit">Add</button>
</div>
</div>
</div>
</form>
{% endblock content %}
Can someone please help me as by clicking the Notes of a particular patient only specific to that user notes has to be displayed as well as to add notes to that patient only.

After doing some R n D i was able to get through it just added a way to pass paramter as URL
<td><a class="btn btn-primary btn-xs" href="{% url 'doctor-add-notes' p.get_name %}">Notes</a></td>
and in Views
def doctor_add_notes_view(request,value):
appointmentForm=forms.PatientNotesForm()
print('value',value)
#notes = models.Notes.objects.all().order_by('-NoteDate')
notes = models.Notes.objects.all().filter(patientName=value).order_by('-NoteDate')
so URL becomes
http://127.0.0.1:8000/doctor-add-notes/P4
this way i was able to solve the problem ( learnt a new thing )

Related

Django Model Form not saving data

I am working on Django application and I am trying to create form for users' suggestions and comments. I want to see that suggestions/comments in database (admin interface). After the comment is submitted, it is not saved in database. I have some mistake here but I don't know where it is. Can you please help me?
views.py:
def komentariPrijedlozi(request):
if request.method == 'POST':
form = CommentsSuggestionsForm(request.POST)
if form.is_valid():
form.save()
return render(request, 'rjecnik/successCommentsSuggestions.html')
form = CommentsSuggestionsForm()
context = {'form' : form}
return render(request, 'rjecnik/komentariPrijedlozi.html', context)
komentariPrijedlozi.html:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Comments and suggestions</title>
</head>
<body>
<section class="main-container1" style=" margin-top: 50px; background-color: lightgray;">
<div class="columns">
<div class="main-par" style="font-size: 21px; margin-bottom: 20px;">Komentari i prijedlozi novih prijevoda:</div>
<div class="column is-half is-offset-one-quarter">
<form method="POST" autocomplete="off" enctype="multipart/form-data">
<tr>
<th>
<label for="suggestion1">Prijedlog novog pojma:</label>
</th>
<td >
<input type="text" name="suggestion1" maxlength="100" autocomplete="off" style="width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block;">
</td>
</tr>
<tr>
<th>
<label for="suggestion2">Prijedlog prijevoda:</label>
</th>
<td>
<input type="text" name="suggestion2" maxlength="100" autocomplete="off" style="width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block;">
</td>
</tr>
<tr>
<th>
<label for="comment">Komentar:</label>
</th>
<td>
<textarea name="comment" cols="40" rows="10" style="width: 100%; padding: 12px 20px; margin: 8px 0; display: inline-block;"></textarea>
</td>
</tr>
{% csrf_token %}
<input type="submit" class="btn-sub" value="Submit">
</form>
</div>
</div>
</div>
</section>
</body>
</html>
models.py:
class CommentsSuggestions(models.Model):
suggestion_word = models.CharField(max_length=100)
suggestion_translation = models.CharField(max_length=100)
comment_suggestion = models.TextField()
forms.py:
class CommentsSuggestionsForm(ModelForm):
class Meta:
model = CommentsSuggestions
fields = '__all__'
urls.py:
path('komentari_i_prijedlozi/', views.komentariPrijedlozi, name="komentariPrijedlozi"),
For as far as I can see you are not using your custom form in your template, change the form in your template to this:
<form method="POST" autocomplete="off" enctype="multipart/form-data">
{% csrf_token %}
{{ form.as_table }}
<input type="submit" class="btn-sub" value="Submit">
</form>
Then the values will be processed correctly when arriving in your views.py.

save() prohibited to prevent data loss due to unsaved related object 'user'

i am trying to save data in a table when a user click the checkout button of add to cart but it is showing me the above mention error i am unable to understand and one more thing is happening when i logout my the cart which i saved also got erased is it shomehow related to that i don't know
here is my views.py for checkout button
class Checkout(View):
def post (self, request,):
user = request.session.get('user')
ids = (list(request.session.get('cart').keys()))
sections = Section.get_sections_by_id(ids)
for section in sections:
order = Order(user = User(id=user),
section = section,
price = section.price,
)
order.save()
my views.py for cart.html
class Cart(View):
def get (self, request):
ids = (list(request.session.get('cart').keys()))
sections = Section.get_sections_by_id(ids)
print(sections)
return render(request, 'cart.html', {'sections': sections})
my urls.py
urlpatterns = [
path('cart/', Cart.as_view(),name='cart'),
path('Check-Out/', Checkout.as_view(),name='checkout'),
]
my cart.html
{% extends 'base.html' %}
{% load static %}
{% load cart %}
{% load custom %}
{% block head %}
<link rel="stylesheet" href="{% static 'css/cart.css' %}">
{% endblock %}
{% block content %}
<div class="container jumbotron">
<section>
<h1>My cart</h1>
<table class="table">
<thead>
<tr>
<th scope="col">S.no</th>
<th scope="col">Subject</th>
<th scope="col">Section</th>
<th scope="col">Teacher</th>
<th scope="col">Duration</th>
<th scope="col">Price</th>
</tr>
</thead>
{% for section in sections%}
<tbody style="margin-bottom: 20px;">
<tr>
<th scope="row">{{forloop.counter}}</th>
<td>{{section.subject.name}}</td>
<td>{{section.title}}</td>
<td>{{section.teacher}}</td>
<td>{{section.content_duration}}</td>
<td>{{section.price|currency}}</td>
</tr>
</tbody>
{% endfor %}
<tfoot>
<tr>
<th> Total</th>
<th></th>
<th></th>
<th></th>
<th></th>
<th>{{sections|total_price:request.session.cart|currency}}</th>
</tr>
<hr>
</tfoot>
</table>
<button type="button" data-toggle="modal" data-target="#exampleModal" style="float: right; margin-left:5px" class="btn btn-outline-primary">Check Out</button>
<button type="button" style="float: right; margin-left:5px" class="btn btn-info">Back To Site</button>
</tfoot>
</section>
</div>
<!-- Modal -->
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Please Verify</h5>
<input type="button"class="btn-close btn-link" style="text-decoration:none; border:none; font-size:20px;" data-dismiss="modal" aria-label="Close" value="X">
</div>
<div class="modal-body">
<form action="{% url 'transactions:checkout' %}" method="Post">
{% csrf_token %}
<input type="submit" class="btn float-right btn-primary" value='Go Ahead'>
</form>
</div>
</div>
</div>
</div>
{% endblock %}
and my models.py
class Order(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE,)
section = models.ForeignKey(Section, on_delete=models.CASCADE )
price = models.FloatField(blank=False)
update_at = models.DateTimeField(auto_now=True, editable=False)
def placeorder(self):
self.save()
please help if you can an
The issue caused by this line:
order = Order(user = User(id=user)
Using User(id=user) means you want to create an unsaved User and use it in an unsaved Order and then saving the order, but this will not work because you haven't saved the User yet, as mentioned by the error.
You can just simply just use the existing user in the order like this:
order = Order(user=user, section=section, price=section.price)
order.save()

Django Template Takes The Information From The Other One

inside of the views.py
def book_detail(request, pk):
book = get_object_or_404(Library, pk=pk)
return render(request, 'book_detail.html', context={'book': book})
def admin_book_detail(request, pk):
book = get_object_or_404(Library, pk=pk)
return render(request, 'admin_book_detail.html', context={'book': book})
Hello, I am new to Django. I have two views like this. One of them is for normal user and the other one is for admin. But the template of admin takes it's information from the other one. Like, If I change the book_detail, admin_book_detail changes too. But if i change admin_book_detail's information, nothing happens.
inside of admin_book_detail.html
{% block content %}
{{ block.super }}
<div style="margin:0 auto;width:1200px;">
<h1 class="page-header" style="color:black;">{{ book.title }}</h1>
<h2> This book is <b>{{ book.availability }}</b> to borrow</h2>
<br>
<h3>Author of the Book = <b>{{ book.author }}</b></h3>
<br>
<h3>Publish Year = <b>{{ book.year }}</b></h3>
<br>
<h3> Category = <b>{{ book.category }}</b></h3>
<div style="padding: 10px 5px;">
<div style="background-color: white;padding: 10px 30px; width:175px;border: 3px solid black;text-align:center;">
<a style="color:black; font-size:19px;" href="{% url 'adminbook' %}"><b>Go Back</b></a>
</div>
</div>
</div>
{% endblock %}
inside of book_detail.html
{% block content %}
{{ block.super }}
<div style="margin:0 auto;width:1200px;">
<h1 class="page-header" style="color:black;">{{ book.title }}</h1>
<h2> This book is <b>{{ book.availability }}</b> to borrow</h2>
<br>
<h3>Author of the Book = <b>{{ book.author }}</b></h3>
<br>
<h3>Publish Year = <b>{{ book.year }}</b></h3>
<br>
<h3> Category = <b>{{ book.category }}</b></h3>
<div style="padding: 10px 5px;">
<div style="background-color: white;padding: 10px 30px; width:175px;border: 3px solid black;text-align:center;">
<a style="color:black; font-size:19px;" href="{% url 'book' %}"><b>Go Back</b></a>
</div>
</div>
{% endblock %}
inside of the url
urlpatterns = [
path('request_book/', request_book, name='request_book'),
re_path(r'book_detail/(?P<pk>[0-9]+)/', book_detail, name='book_detail'),
re_path(r'admin_book_detail/(?P<pk>[0-9]+)/', admin_book_detail, name='admin_book_detail'),
path('add_book/', add_book, name='add_book')
]
Edit : Ok I fixed it.
What I can see is that both of your views does the same thing. So it really won't matter whichever view you call.
It's different on the HTML page on basis of how you want to represent that information.
They both access the same object without any specific filter, so they're going to return the same object. If you are looking to display different filtered results, you need to change the query.

Form not displaying on Django site

I have just started learning Django and I have hit a little snag and was hoping someone could help.
Problem:
My form is not displaying in my main HTML template (ingredior.html) but the form will display in my test HTML template (test.html) which is just a boiler plate HTML file with the {{form1}} tag in the body. I am changing "return render(request, 'ingredior/ingredior.html', context)" in the views.py file manually to test the two different HTML templates.
ingredior.html
test.html
Question:
Why is the form working in the test.html and not the ingredior.html file when changed?
Please keep in mind that I am swapping this line of code "return render(request, 'ingredior/ingredior.html', context)" with "return render(request, 'ingredior/test.html', context)" to test between the two.
CODE---------
Forms.py
from django import forms
class UserInput(forms.Form):
base_search_ingredient = forms.ChoiceField(choices=[('vegan', 'Vegan'), ('vegatarian', 'Vegatarian')])
views.py
from django.shortcuts import render
import requests
from .local_api_key import Key
from .forms import UserInput
def index (request):
app_id = Key.app_id
app_key = Key.app_key
search_from = 0
search_to = 100
form1 = UserInput()
test = []
if request.POST.get('search'):
test2 = request.POST.get('search')
intolerance = test2
url = requests.get(f"https://api.edamam.com/search?q={intolerance}&excluded=egg&excluded=beef&excluded=dairy&excluded=tomato&excluded=cherry%20tomatoes&excluded=rice&excluded=corn&excluded=soy&excluded=onion&from={search_from}&to={search_to}&health={intolerance}&app_id={app_id}&app_key={app_key}").json()
recipe_length = (len(url['hits']))
else:
intolerance = 'vegan'
url = requests.get(f"https://api.edamam.com/search?q={intolerance}&excluded=egg&excluded=beef&excluded=dairy&excluded=tomato&excluded=cherry%20tomatoes&excluded=rice&excluded=corn&excluded=soy&excluded=onion&from={search_from}&to={search_to}&health={intolerance}&app_id={app_id}&app_key={app_key}").json()
recipe_length = (len(url['hits']))
for urls in range(recipe_length):
recipe_name = (url['hits'][urls]['recipe']['label'])
recipe_url = (url['hits'][urls]['recipe']['url'])
recipe_image = (url['hits'][urls]['recipe']['image'])
recipe_healthLabels = (url['hits'][urls]['recipe']['healthLabels'])
recipe_ingredients = (url['hits'][urls]['recipe']['ingredientLines'])
test.append((recipe_name, recipe_url, recipe_image, recipe_healthLabels, recipe_ingredients))
context = {'test': test, 'form1': form1}
return render(request, 'ingredior/ingredior.html', context)
ingredior.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Nake Recipes</title>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<link rel="stylesheet" href=>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style>
.card {
width: 300px;
height: 700px;
overflow: scroll;
float: left;
margin: 13px;
}
.list {
line-height: 2em;
text-align: left;
}
.card-content ul {
height: 100px
overflow-y: scroll;
}
.container h1 {
text-align: center;
}
</style>
</head>
<body>
<nav>
<div class="container nav-wrapper">
Naked Recipes
<ul id="nav-mobile" class="right">
<li>Home</li>
</ul>
</div>
</nav>
<div class="container">
<h1 style="text-align: c">What intolerance do you have?</h1>
<div class="row">
<div class="col s4">
<!-- Promo Content 1 goes here -->
<div class="center">
<i class="large material-icons" style="color: #EE6E73">flash_on</i>
<p></p>
<p class="light center"></p>
</div>
</div>
<div class="col s4">
<!-- Promo Content 2 goes here -->
<div class="center">
<i class="large material-icons" style="color: orange">camera</i>
<p></p>
<p class="light center"></p>
</div>
</div>
<div class="col s4">
<!-- Promo Content 3 goes here -->
<div class="center">
<i class="large material-icons" style="color: blue">chrome_reader_mode</i>
<p></p>
<p class="light center"></p>
</div>
</div>
</div>
<br>
<form action="" method="post">
{% csrf_token %}
{{ form1 }}
</form>
<br>
<div class="row">
{% for item in test %}
<div class="col_s2">
<div class="card">
<div class="card-image">
<img src= {{ item.2 }} alt="">
</div>
<div class="card-content scroll">
{{ item.0 }}<br><br>
<p>
<b>Ingredients</b><br>
</p>
<ul class="list">
{% for litem in item.4 %}
<li>- {{ litem }}</li>
{% endfor %}
</ul>
<ul class="list">
<p>
<b>Allergies</b>
</p>
{% for litem in item.3 %}
<li>- {{ litem }}</li>
{% endfor %}
</ul>
</div>
<div class="card-action">
<a href={{ item.1 }}>Get Full Recipe </a>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
</body>
</html>
test.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="" method="post" >
{% csrf_token %}
{{ form1 }}
</form>
</body>
</html>
app/urls.py
from django.urls import path
from . import views
urlpatterns = [
path('', views.index, name="index"),
]
Thank you in advance 😅
** UPDATE **
On further investigation :
Inspection Image ingredior.html
Inspection Image test.html
They are the same.

Show list depending class (Django)

I have the following problem.
<div class="variable">
<ul class="1">
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
<li>1</li>
</ul>
<ul class="2">
<li>2</li>
<li>2</li>
<li>2</li>
<li>2</li>
<li>2</li>
</ul>
<ul class="3">
<li>3</li>
<li>3</li>
<li>3</li>
<li>3</li>
<li>3</li>
</ul>
<ul class="4">
<li>4</li>
<li>4</li>
<li>4</li>
<li>4</li>
<li>4</li>
</ul>
<ul class="5">
<li>5</li>
<li>5</li>
<li>5</li>
<li>5</li>
<li>5</li>
</ul>
</div>
I need that when "variable" is for example "1" list only shows "1".
Is possible?
I need to display a list depending on the class of the DIV. The DIV class is variable, generates my system, but no problem, since the set as ordinary HTML.
Regards
UPGRADE
I'm use web in Django.
I have get a list of the ID of the category. I wanted to put that DIV ID in order to display only the list match that number.
As you comment that I can not use numbers, I have to use the name, the problem is that a category called "LOGITECH MICE" and the class does not allow me to put a space, any solution?
My Django template is:
{% load i18n %}
{% load thumbnail %}
{% load modules %}
{% module {category_decription|catalog.right} id="sidebar" class="block" %}
<div style="float:right; width: 700px; margin-right: 10px; margin-bottom: 10px;" id="slider">
<div><img border="0" src="/../../static/banners_productos/{{ query.id }}/01.jpg" ></img></div>
</div>
<style>
ul.marcas{
display: none;
}
div.SMARTPHONES ul{
display: none;
color: green;
}
div.SMARTPHONES ul.SMARTPHONES{
display: block;
}
div.FAX ul{
display: none;
color: green;
}
div.FAX ul.FAX{
display: block;
}
.fabricante { display: inline; }
</style>
<div style="background-color:#fff;" id="content">
<div id="catalog-category" class="block clearfix">
<!--div class="catalog-head"-->
<div class="toolbar toolbar-top">
<span style=" float: left;" class="view-mode">Productos : {{ values|length }}/{{ total }}</span>
<div class="items-pager">
<span class="items-drop"><select onchange="setLocation('paginator',this.value)">{% for item in paginator_items %}<option value="{{ item }}"{% if paginator_option == item %} selected="selected"{% endif %}>{{ item }}</option>{% endfor %}</select> Mostrar</span>
</div>
<!--div style="float: left; margin-left: 25px;"><span class="view-mode">Stock </span><a style="color:#1D9107;" href="?available=1">OK</a><a style="color:#f00;" href="?available=0">NO</a></div-->
<div class="items-sort">
<span class="sort-drop">Ordenar por
<select onchange="setLocation('order',this.value)">{% for order in catalog_orders %}<option value="{{ order }}"{% if order_option == order %} selected="selected"{% endif %}>{% trans order %}</option>{% endfor %}</select>
{% if order_by_option = 'desc' %}<a style="color:#fff; margin-left: 15px;" href="#" onclick="setLocation('order_by','asc')">Descendente<img style="height: 22px; float: right; margin-left: 4px; margin-right: 15px;" border="0" src="/../../static/asce.png" ></img></a>{% else %}<a style="color: #FFF !important; margin-left: 15px;" href="#" onclick="setLocation('order_by','desc')">Ascendente<img style="height: 22px; float: right; margin-left: 4px; margin-right: 15px; " src="/../../static/des.png" ></img></a>{% endif %}</span>
</div>
</div>
{% if values|length == 0 %}<p class="note-msg">{% trans "No existen productos en esta categoria." %}</p>{% endif %}
<!--/div-->
<!--div class="catalog-body"-->
<div style="height: 40px; margin-top: -10px; padding: 10px; height: 30px;" class="{{ query.name }}">
<ul class="marcas FAX">
<li class="fabricante">BROTHER</li>
</ul>
<ul class="marcas IMPRESORAS">
<li class="fabricante">HP</li>
<li class="fabricante">BROTHER</li>
<li class="fabricante">EPSON</li>
</ul>
<ul class="marcas SMARTPHONES">
<li class="fabricante">TP LINK</li>
<li class="fabricante">TENDA</li>
<li class="fabricante">{{ query.id }}</li>
</ul>
</div>
{% if mode_option == 'list' %}
<ul id="catalog-list">{% for value in values %}
<li id="product-{{value.product.id}}" class="product-item block clearfix">
<div class="product-detail">
<div>
<img src="{% thumbnail value.base_image.url 150x150 product_zoook.png %}" title="{{value.name}}" />
</div>
<div style="width: 420px; float: left; height: 15px; overflow: hidden;"><h2>{{value.name}}</h2></div>
<div style="width: 365px; float:left;">
<div style="height: 35px; float:left;"></div>
<div style="width: 50%; float: left; height: 15px; font-size: 10px;">Ref: {{value.code}}</h2></div>
<div style="width: 50%; float: left; height: 15px; font-size: 10px;">Part Number: {{value.variants}}</h2></div>
<div style="width: 50%; float: left; height: 15px; font-size: 10px;">Categoria: {{ query.name }}</h2></div>
<div style="width: 110px; float: left;font-size: 10px;">
<img style="height: 22px; float: left; margin-top: 7px;" src="../../../../static/images/info_ico.png" />
</div>
</div>
<div style="width: 150px; float: right;">
{% if value.status %}
{% if value.product.available %}
<img style="height: 15px; margin-top: -16px; margin-left: 79px; margin-bottom: 14px;" src="../../../../static/images/ok.jpg" />
{% else %}
<img style="height: 15px; margin-top: -16px; margin-left: 79px; margin-bottom: 14px;" src="../../../../static/images/ok.jpg" />
{% endif %}
{% else %}
</div>
<div class="out-service ico border3b"><h3>{% trans "This product is out of service" %}</h3></div>
{% endif %}
{% if user.is_authenticated %}
<div id="product-price-{{value.product.id}}" class="price-box">
<span class="regular-price">
<span class="price3">
{% if currency_position == 'before' %}{{ currency }} {{value.price}}{% else %}{{value.price}} {{ currency }}{% endif %}
</span>
</span>
</div>
</div>
{% else %}
<a style="margin-right: 12px; width: 90px; float: right; height: 16px; padding: 5px; margin-top: 5px; background-image: url('/static/images/menu_pequeño/reg.jpg');" class="boton5" href="http://www.broadband-technologies.es/es/partner/login"><span style="padding-left: 20px;"></span></a>
{% endif %}
</li>{% endfor %}
</ul>
{% endif %}
<!--/div--></div>
{% if product_products.paginator.num_pages > 1 %}
<div id="paginator" class="pagination toolbar-bottom">
<span class="step-links">
{% if product_products.has_previous %}
{% trans "Previous" %}
{% endif %}
<span class="current">
{% trans "Page" %} {{ product_products.number }} DE {{ product_products.paginator.num_pages }}
</span>
{% if product_products.has_next %}
{% trans "Next" %}
{% endif %}
</span>
</div>{% endif %}
</div>
<!--/div-->
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.zproduct.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.fancybox-1.3.4.pack.js"></script>
{% if update_price and user.is_authenticated and values|length > 0 %}<script type="text/javascript" src="{{ STATIC_URL }}js/jquery.zupdateprice.js"></script>{% endif %}
You may get a list of the categories? Easier ... to display only manufacturers that contain a category?
My main problem is this (that's why I ask the code).:
- I have a page in Django
- I products, categories and manufacturers.
- I want to take, when you are in a category, a list of manufacturers who have products in that category.
Best Regards
First of all - CSS class shouldn't be a pure integer. So I use letters in my answer since numbers doesn't work. Normally it should be something more descriptive though.
Define CSS rules like:
div.a ul{
display: none;
color: green;
}
div.a ul.a{
display: block;
}
div.c ul{
display: none;
color: red;
}
div.c ul.c{
display: block;
}
Here is the fiddle - http://jsfiddle.net/FC6vF/
The color rule is just to mark the difference in the fiddle and you can omit this.
For Django template - put this code:
{% for css_class in fancy_css_classes %}
div.{{ css_class }} ul{
display: none;
color: red;
}
div.{{ css_class }} ul.{{ css_class }}{
display: block;
}
{% endfor %}
inside <style>...</style> tag and pass the list of classes as a context variable fancy_css_classes from your view.