I have a table of employees. I am loading data using $http and using ng-repeat to print it on the webpage. I want to edit each row content.
HTML:
tbody ng-repeat="list in data" >
<tr ng-hide="edit" ng-click="edit=true">
{% verbatim %}
<td> {{$index + 1}}</td>
<td>{{ list.associate_nbr }}</td>
<td>{{ list.per }}%</td>
<td>{{ list.count }}</td>
<td>{{ list.sample_per }}%</td>
<td>{{ list.sample}}</td>
<td><input type="text" value="{{ list.focused
}}"></td>
<td><input type="text" value="{{
list.random_field }}"></td>
</tr>
{% endverbatim %}
MAIN.JS
(function(){
'use strict';
angular.module('sampling.demo',[])
.controller('SamplingController', ['$scope','$http',SamplingController]);
function SamplingController($scope,$http)
{
$scope.data = [];
$http.get('/sample/').then(function(response){
$scope.data = response.data;
});
}
}());
I want to edit the last two fields when user clicks on it.
Related
1 2 3
I'm trying to get data in the form of a table, but the data is not being fetched, I don't know how to get the record, I'm using cloud firestore to get the data.
In my code I have used {{buldings.building}} to get the record but this is not fetching the record from the firebase.
here is my table code for table
<div class="row">
<div class="col-lg-12 mb-4">
<!-- Simple Tables -->
<div class="card">
<div class="card-header py-3 d-flex flex-row align-items-center justify-content-between">
<i class="fas fa-plus-circle "></i> Add Building
</div>
<div class="table-responsive">
<table class="table align-items-center table-flush" id="buildingList">
<thead class="thead-light">
<tr>
<th>BUILDING NAME</th>
<th>POSTAL CODE</th>
<th>CITY</th>
<th>STREET</th>
<th>HOUSE NO.</th>
<th>TOWN</th>
<th>ADDITIONAL INFO</th>
<th colspan="2">ACTION</th>
</tr>
</thead>
<tbody>
{% for building in buildings %}
<tr>
<td>{{ buildings.building }}</td>
<td>{{ buildings.postalCode }}</td>
<td>{{ buildings.city }}</td>
<td>{{ buildings.houseNo }}</td>
<td>{{ buildings.street }}</td>
<td>{{ buildings.town }}</td>
<td>{{ buildings.additionalInfo }}</td>
<td></i>Edit</p></td>
<td></i>Delete</p></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<div class="card-footer"></div>
</div>
</div>
</div>
</div>
<!---Container Fluid-->
</div>
views.py file
def buildingMag(request):
context = {
'buildings': db.collection('Buildings').get()
}
return render(request,"EmployeeAdmin/buildingMag.html",context)
db.collection('Buildings').get() should return you a list of Firestore DocumentSnapshot which is sent to template context via buildings key. Looping through the buildings will let you populate the template(table) with each item on the list. Something like below.
In your views construct the dict from DocumentSnapshot and return the dict
views.py
buildings = db.collection('Buildings').get()
context = {
'buildings': [building.to_dict() for building in buildings]
}
template.html
{% for building_obj in buildings %}
<tr>
<td>{{ building_obj.building }}</td>
<td>{{ building_obj.postalCode }}</td>
<td>{{ building_obj.city }}</td>
...
...
</tr>
{% endfor %}
I am trying to delete severals rows at the same time in django.
How can I simply change the state of the booleanfield 'to_delete', just by clicking on the checkbox?
I am using datatables. The way how I am doing it is to create a boolean to_delete in my model, when the checkbox is selected, I am calling the function delete_multiple_company in my view. However, this doesn`t work. Any idea, what I am doing wrong please. Many Thanks,
I`ve created my view:
views.py
def delete_multiple_company(request, company_id):
company = get_object_or_404(Company, pk=company_id)
company = Company.objects.get(pk=company_id)
company.objects.filter(to_delete=True).delete()
return HttpResponseRedirect(reverse("company:index_company"))
urls.py
url(r'^(?P<company_id>[0-9]+)/delete_multiple_company/$', views.delete_multiple_company, name='delete_multiple_company'),
models.py
class Company(models.Model):
to_delete = models.BooleanField(default=False)
index.html
<span class="fa fa-plus"></span>Delete Companies
<table id="dtBasicExample" class="table table-striped table-hover">
<thead>
<tr>
<th>Select</th>
<th>#</th>
<th>Checked ?</th>
</tr>
</thead>
<tbody>
{% for company in companys.all %}
<tr>
<td id="{{ company.id }}"><input type="checkbox" class="companyCheckbox" name="checkedbox" id="{{ company.id }}" value="{{ company.id }}"></td>
<td>{{ company.id }}</td>
<td>{{ company.to_delete }}</td>
</tr>
{% endfor %}
</tbody>
</table>
I experienced a similar issue as you, what I did was put in a form.
index.py
<form method="POST" class="post-form">{% csrf_token %}
<button type="submit" class="save btn btn-default">Delete</button>
<span class="fa fa-plus"></span>Delete Companies</a>
<table id="dtBasicExample" class="table table-striped table-hover">
<thead>
<tr>
<th>Select</th>
<th>#</th>
<th>Checked ?</th>
</tr>
</thead>
<tbody>
{% for company in companys.all %}
<tr>
<td id="{{ company.id }}"><input type="checkbox" class="companyCheckbox" name="checkedbox" id="{{ company.id }}" value="{{ company.id }}"></td>
<td>{{ company.id }}</td>
<td>{{ company.to_delete }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<button type="submit" class="save btn btn-default">Delete</button>
</form>
Clicking on the button then triggered the POST method in my view.
views.py
def index(request):
if request.method == 'POST':
print('I made it here')
# Put your code here, note you will return a dict, so some trial and error should be expected
I have a template that is rendered by generic List View. I want to give a download link in front of each row of data in table. The download link will create a PDF file of respective rows data. Please tell me how to write a code for that?
Views.py
class BookingConfirmationListView(LoginRequiredMixin, generic.ListView):
model = container_booking
template_name = 'home/booking_confirmation_detail.html'
context_object_name = 'all_container'
def get_queryset(self):
return container_booking.objects.all()
Templates look like
<table class="table-striped table-hover table-bordered" width="100%">
<tr>
<th>Date</th>
<th>Source</th>
<th>Destination</th>
<th>Container</th>
<th>Commodity</th>
<th>Agreed Rate</th>
<th>Edit</th>
<th>Delete</th>
<th>Status</th>
</tr>
{% for item in all_container %}
<tr>
<td>{{ item.date }} </td>
<td>{{ item.place_of_reciept }} </td>
<td>{{ item.final_place_of_destination }} </td>
<td>{{ item.equipment_type }}{{ item.quantity }} </td>
<td>{{ item.commodity }} </td>
<td>{{ item.agreed_rate }} </td>
<td><a href="{% url 'home:cont_bk-update' item.id %}" ><i class="fas
fa-edit"></i></a></td>
<td><a href="{% url 'home:cont_bk-delete' item.id %}" ><i class="fas
fa-trash"></i></a></td>
<td>{{ item.approved }}</td>
</tr>
{% endfor %}
</table>
urls.py
url(r'^cont_bkdetail$', views.BookingConfirmationListView.as_view(),
name='cont_bk-detail'),
url(r'^cont_bk/(?P<pk>[0-9]+)/$',
views.BookingConfirmationUpdate.as_view(), name='cont_bk-update'),
url(r'^cont_bk/(?P<pk>[0-9]+)/delete/$',
views.BookingConfirmationDelete.as_view(), name='cont_bk-delete'),
I want that whenever I click download, the PDF file of that row is generated.
code is:
def get_case():
...
table_step = zip(li_host,li_cmd)
return render_template('auto.html',table_step = table_step)
html is:
{% for row in table_step %}
<tr>
<td>{{ row[0]|safe }}</td>
<td>{{ row[1]|safe }}</td>
<td><button type="button" class="btn btn-default"> 编辑 </button></td>
</tr>
{% endfor %}
actual page shows no content:
I'm getting a little issue and I don't remember the way to solve my problem.
I have a template which let to query database and get a result according to user's criteria.
My view looks like :
#login_required
def Identity_Individu_Researching(request) :
query_lastname_ID = request.GET.get('q1ID')
query_firstname_ID = request.GET.get('q1bisID')
query_naissance_ID = request.GET.get('q1terID')
sort_params = {}
set_if_not_none(sort_params, 'id__gt', query_lastname_ID)
set_if_not_none(sort_params, 'Prenom__icontains', query_firstname_ID)
set_if_not_none(sort_params, 'VilleNaissance', query_naissance_ID)
query_ID_list = Individu.objects.filter(**sort_params)
return render(request, 'Identity_Individu_Recherche.html', context)
But this request is launched automatically when the template is loaded.
In my HTML template, I have :
<form autocomplete="off" method="GET" action="">
<input type="text" name="q1ID" placeholder="Nom (ex:TEST) " value="{{ request.GET.q1ID }}"> et
<input type="text" name="q1bisID" placeholder="Prénom (ex:Test)" value="{{ request.GET.q1bisID }}">
<input type="text" name="q1terID" placeholder="Ville Naissance" value="{{ request.GET.q1terID }}"> (optionnel)
<input class="button" type="submit" name="recherche" value="Rechercher">
</form>
<br></br>
<table style="width:120%">
<tbody>
<tr>
<th>ID</th>
<th>État</th>
<th>N° Identification</th>
<th>Civilité</th>
<th>Nom</th>
<th>Prénom</th>
<th>Date de Naissance</th>
<th>Ville de Naissance</th>
<th>Pays de Naissance</th>
<th>Institution</th>
</tr>
{% for item in query_ID_list %}
<tr>
<td>{{ item.id}}</td>
<td>{{ item.Etat}}</td>
<td>{{ item.NumeroIdentification}}</td>
<td>{{ item.Civilite }}</td>
<td>{{ item.Nom }}</td>
<td>{{ item.Prenom }}</td>
<td>{{ item.DateNaissance }}</td>
<td>{{ item.VilleNaissance }}</td>
<td>{{ item.PaysNaissance }}</td>
<td>{{ item.InformationsInstitution }}</td>
</tr>
{% endfor %}
</tbody>
</table>
So How I can launch the queryset only if user submit the form with the form button ? I know it's based on name = "jhjh"
You should check if the request contains the form data.
if 'recherche' in request.GET:
...
You can change method for your form in template
<form autocomplete="off" method="POST" action="">
<!-- ^^^^^ -->
in the view:
query_ID_list = Individu.objects.all()
if request.method == 'POST':
# your logic
query_ID_list = query_ID_list.filter(**sort_params)
return render(request, 'Identity_Individu_Recherche.html', context)