django app that i click on a button to put is_active to false for a specific record. I…
- User
django app that i click on a button to put is_active to false for a specific record. I need models.py, urls.py, views.py and tempates
- Assistant
models.py:
from django.db import models class Record(models.Model): name = models.CharField(max_length=100) is_active = models.BooleanField(default=True) def __str__(self): return self.nameurls.py:
from django.urls import path from .views import deactivate_record urlpatterns = [ path('deactivate-record/<int:pk>/', deactivate_record, name='deactivate_record'), ]views.py:
from django.shortcuts import render, get_object_or_404 from django.http import HttpResponseRedirect from django.urls import reverse from .models import Record def deactivate_record(request, pk): record = get_object_or_404(Record, pk=pk) if request.method == 'POST': record.is_active = False record.save() return HttpResponseRedirect(reverse('record_list')) return render(request, 'deactivate_record.html', {'record': record})templates/deactivate_record.html:
<h1>Deactivate Record</h1> <p>Are you sure you want to deactivate the record "{{ record }}"?</p> <form method="post"> {% csrf_token %} <button type="submit">Yes</button> <a href="{% url 'record_list' %}">No</a> </form> - User
django app having a card with two button, one to open detail and another to change the value of is_active to false for a specific record. Ineed models.py, urls.py, views.py and templates
- Assistant
models.py:
from django.db import models class Record(models.Model): name = models.CharField(max_length=100) is_active = models.BooleanField(default=True) def __str__(self): return self.name - User
django app having record and two button as a dashboard. One buttonto see the detail of the record and another to put is_active to false for the specific record. I need models.py, urls.py, views.py and tempates
- Assistant