add forms and views for the ComputerCpuRelation
This commit is contained in:
parent
1aa48a7109
commit
3311619ef7
|
@ -3,6 +3,7 @@ import floppyforms.__future__ as forms
|
|||
from core import utils
|
||||
|
||||
from computers.models import Computer
|
||||
from computers.models import ComputerCpuRelation
|
||||
from computers.models import ComputerRamRelation
|
||||
|
||||
|
||||
|
@ -41,3 +42,14 @@ class ComputerRamRelationCreateForm(forms.ModelForm):
|
|||
class Meta:
|
||||
model = ComputerRamRelation
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
class ComputerCpuRelationCreateForm(forms.ModelForm):
|
||||
"""
|
||||
Basic form class to use crispies HTML5 forms.
|
||||
"""
|
||||
class Meta:
|
||||
model = ComputerCpuRelation
|
||||
fields = '__all__'
|
||||
|
||||
|
||||
|
|
|
@ -73,9 +73,9 @@
|
|||
<div class="card-body">
|
||||
<p><b>CPUs:</b></p>
|
||||
{% for cpu in cpu_relations %}
|
||||
{{ cpu.amount }}x {{ cpu.cpu }}<br>
|
||||
{{ cpu.amount }}x {{ cpu.cpu }} <a href="{% url 'cpu_relation_delete' cpu.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 'cpu_relation_create' pk %}" class="add" title="Add" data-toggle="tooltip"><i class="material-icons">add</i></a></p>
|
||||
|
||||
<p><b>GPUs:</b></p>
|
||||
{% for gpu in gpu_relations %}
|
||||
|
|
|
@ -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 %}
|
|
@ -26,4 +26,10 @@ urlpatterns = [
|
|||
path('delete/ram-relation/<int:pk>/',
|
||||
views.ComputerRamRelationDeleteView.as_view(),
|
||||
name='ram_relation_delete'),
|
||||
path('create/cpu-relation/<int:pk>/',
|
||||
views.ComputerCpuRelationCreateView.as_view(),
|
||||
name='cpu_relation_create'),
|
||||
path('delete/cpu-relation/<int:pk>/',
|
||||
views.ComputerCpuRelationDeleteView.as_view(),
|
||||
name='cpu_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 ComputerCpuRelationCreateForm
|
||||
from .forms import ComputerRamRelationCreateForm
|
||||
from .models import Computer
|
||||
from .models import ComputerCpuRelation
|
||||
|
@ -163,6 +164,33 @@ class ComputerRamRelationDeleteView(LoginRequiredMixin, DeleteView):
|
|||
return reverse('computer', args=(self.object.computer.pk,))
|
||||
|
||||
|
||||
class ComputerCpuRelationCreateView(LoginRequiredMixin, CreateView):
|
||||
model = ComputerCpuRelation
|
||||
form_class = ComputerCpuRelationCreateForm
|
||||
template_name = 'computers/cpu_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 ComputerCpuRelationDeleteView(LoginRequiredMixin, DeleteView):
|
||||
model = ComputerCpuRelation
|
||||
template_name = 'computers/relation_confirm_delete.html'
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('computer', args=(self.object.computer.pk,))
|
||||
|
||||
|
||||
|
||||
def get_success_url(self):
|
||||
return reverse('computer', args=(self.object.computer.pk,))
|
||||
|
|
Loading…
Reference in New Issue