diff --git a/computers/forms.py b/computers/forms.py index 7b8b7c4..86a490c 100644 --- a/computers/forms.py +++ b/computers/forms.py @@ -4,6 +4,7 @@ from core import utils from computers.models import Computer from computers.models import ComputerCpuRelation +from computers.models import ComputerGpuRelation from computers.models import ComputerRamRelation @@ -53,3 +54,12 @@ class ComputerCpuRelationCreateForm(forms.ModelForm): fields = '__all__' +class ComputerGpuRelationCreateForm(forms.ModelForm): + """ + Basic form class to use crispies HTML5 forms. + """ + class Meta: + model = ComputerGpuRelation + fields = '__all__' + + diff --git a/computers/templates/computers/computer_details.html b/computers/templates/computers/computer_details.html index 8db10ea..9443519 100644 --- a/computers/templates/computers/computer_details.html +++ b/computers/templates/computers/computer_details.html @@ -79,9 +79,9 @@

GPUs:

{% for gpu in gpu_relations %} - {{ gpu.amount }}x {{ gpu.gpu }}
+ {{ gpu.amount }}x {{ gpu.gpu }} clear
{% endfor %} -

add

+

add

RAM Modules:

{% for module in ram_relations %} diff --git a/computers/templates/computers/gpu_relation_create.html b/computers/templates/computers/gpu_relation_create.html new file mode 100644 index 0000000..9d3a336 --- /dev/null +++ b/computers/templates/computers/gpu_relation_create.html @@ -0,0 +1,14 @@ +{% extends "core/base.html" %} +{% load crispy_forms_tags %} + +{% block section_title %}Add RAM{% endblock %} +{% block content %} +
+
+ {% csrf_token %} + {{ form|crispy }} + + Cancel +
+
+{% endblock %} diff --git a/computers/urls.py b/computers/urls.py index f2daa72..cb43720 100644 --- a/computers/urls.py +++ b/computers/urls.py @@ -32,4 +32,10 @@ urlpatterns = [ path('delete/cpu-relation//', views.ComputerCpuRelationDeleteView.as_view(), name='cpu_relation_delete'), + path('create/gpu-relation//', + views.ComputerGpuRelationCreateView.as_view(), + name='gpu_relation_create'), + path('delete/gpu-relation//', + views.ComputerGpuRelationDeleteView.as_view(), + name='gpu_relation_delete'), ] diff --git a/computers/views.py b/computers/views.py index 1f04c57..ca13ded 100644 --- a/computers/views.py +++ b/computers/views.py @@ -24,6 +24,7 @@ from .filters import ComputerFilter from .forms import ComputerCreateForm from .forms import ComputerUpdateForm from .forms import ComputerCpuRelationCreateForm +from .forms import ComputerGpuRelationCreateForm from .forms import ComputerRamRelationCreateForm from .models import Computer from .models import ComputerCpuRelation @@ -191,6 +192,33 @@ class ComputerCpuRelationDeleteView(LoginRequiredMixin, DeleteView): return reverse('computer', args=(self.object.computer.pk,)) +class ComputerGpuRelationCreateView(LoginRequiredMixin, CreateView): + model = ComputerGpuRelation + form_class = ComputerGpuRelationCreateForm + template_name = 'computers/gpu_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 ComputerGpuRelationDeleteView(LoginRequiredMixin, DeleteView): + model = ComputerGpuRelation + 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,))