add delete and create views for the ram relation
This commit is contained in:
parent
17a67fda8c
commit
7717255f18
|
@ -3,6 +3,7 @@ import floppyforms.__future__ as forms
|
|||
from core import utils
|
||||
|
||||
from computers.models import Computer
|
||||
from computers.models import ComputerRamRelation
|
||||
|
||||
|
||||
class ComputerCreateForm(forms.ModelForm):
|
||||
|
@ -31,3 +32,12 @@ class ComputerUpdateForm(forms.ModelForm):
|
|||
model = Computer
|
||||
fields = '__all__'
|
||||
exclude = ('net', 'cpu', 'ram', 'gpu', 'disks', 'software')
|
||||
|
||||
|
||||
class ComputerRamRelationCreateForm(forms.ModelForm):
|
||||
"""
|
||||
Basic form class to use crispies HTML5 forms.
|
||||
"""
|
||||
class Meta:
|
||||
model = ComputerRamRelation
|
||||
fields = '__all__'
|
||||
|
|
|
@ -85,9 +85,9 @@
|
|||
|
||||
<p><b>RAM Modules:</b></p>
|
||||
{% for module in ram_relations %}
|
||||
{{ module.amount }}x {{ module.ram }}<br>
|
||||
{{ module.amount }}x {{ module.ram }} <a href="{% url 'ram_relation_delete' module.pk %}" class="delete" title="Delete" data-toggle="tooltip"><i class="material-icons">clear</i></a><br>
|
||||
{% endfor %}
|
||||
<p><a href="{% url 'warranty_create' pk %}" class="add" title="Add" data-toggle="tooltip"><i class="material-icons">add</i></a></p>
|
||||
<p><a href="{% url 'ram_relation_create' pk %}" class="add" title="Add" data-toggle="tooltip"><i class="material-icons">add</i></a></p>
|
||||
|
||||
<p><b>Disks:</b></p>
|
||||
{% for disk in disks_relations %}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
{% extends "core/base.html" %}
|
||||
{% block section_title %}Remove RAM Module{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<form method="post">{% csrf_token %}
|
||||
<p>Are you sure you want to remove the RAM module from "{{ object }}"?</p>
|
||||
<button type="submit" class="btn btn-danger">Delete</button>
|
||||
<a href="{{ request.META.HTTP_REFERER }}" class="btn btn-primary">Cancel</a>
|
||||
<input type="hidden" id="previous_page" name="previous_page" value="/previous/page/url">
|
||||
</form>
|
||||
<script>
|
||||
prev = document.getElementById("previous_page");
|
||||
prev.value = document.referrer;
|
||||
</script>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -0,0 +1,14 @@
|
|||
{% extends "core/base.html" %}
|
||||
{% load crispy_forms_tags %}
|
||||
|
||||
{% block section_title %}Add RAM{% endblock %}
|
||||
{% block content %}
|
||||
<div class="row">
|
||||
<form method="post">
|
||||
{% csrf_token %}
|
||||
{{ form|crispy }}
|
||||
<input type="submit" value="Save" class="btn btn-primary">
|
||||
<a href="{% url 'computer' view.kwargs.pk %}" class="btn btn-secondary">Cancel</a>
|
||||
</form>
|
||||
</div>
|
||||
{% endblock %}
|
|
@ -20,4 +20,10 @@ urlpatterns = [
|
|||
name='computer_update'),
|
||||
path('delete/computer/<int:pk>/', views.ComputerDeleteView.as_view(),
|
||||
name='computer_delete'),
|
||||
path('create/ram-relation/<int:pk>/',
|
||||
views.ComputerRamRelationCreateView.as_view(),
|
||||
name='ram_relation_create'),
|
||||
path('delete/ram-relation/<int:pk>/',
|
||||
views.ComputerRamRelationDeleteView.as_view(),
|
||||
name='ram_relation_delete'),
|
||||
]
|
||||
|
|
|
@ -23,6 +23,7 @@ from .decorators import computer_view_permission
|
|||
from .filters import ComputerFilter
|
||||
from .forms import ComputerCreateForm
|
||||
from .forms import ComputerUpdateForm
|
||||
from .forms import ComputerRamRelationCreateForm
|
||||
from .models import Computer
|
||||
from .models import ComputerCpuRelation
|
||||
from .models import ComputerDiskRelation
|
||||
|
@ -135,3 +136,28 @@ class ComputerDeleteView(LoginRequiredMixin, DeleteView):
|
|||
return reverse('computers', args=(self.object.customer.pk,))
|
||||
|
||||
|
||||
class ComputerRamRelationCreateView(LoginRequiredMixin, CreateView):
|
||||
model = ComputerRamRelation
|
||||
form_class = ComputerRamRelationCreateForm
|
||||
template_name = 'computers/ram_relation_create.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('computer', args=(self.computer.pk,))
|
||||
|
||||
def get_initial(self):
|
||||
"""
|
||||
Set the device and customer dropdown to the device from the previous
|
||||
view and the customer related to the device.
|
||||
"""
|
||||
self.computer = get_object_or_404(Computer, id=self.kwargs.get('pk'))
|
||||
return {
|
||||
'computer': self.computer,
|
||||
}
|
||||
|
||||
|
||||
class ComputerRamRelationDeleteView(LoginRequiredMixin, DeleteView):
|
||||
model = ComputerRamRelation
|
||||
template_name = 'computers/ram_relation_confirm_delete.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('computer', args=(self.object.computer.pk,))
|
||||
|
|
Loading…
Reference in New Issue