diff options
Diffstat (limited to '')
-rw-r--r-- | ctrack/caf/forms.py | 19 | ||||
-rw-r--r-- | ctrack/caf/migrations/0002_auto_20200207_1622.py | 19 | ||||
-rw-r--r-- | ctrack/caf/models.py | 2 | ||||
-rw-r--r-- | ctrack/caf/urls.py | 5 | ||||
-rw-r--r-- | ctrack/caf/views.py | 7 |
5 files changed, 46 insertions, 6 deletions
diff --git a/ctrack/caf/forms.py b/ctrack/caf/forms.py index ee3bf21..34826be 100644 --- a/ctrack/caf/forms.py +++ b/ctrack/caf/forms.py @@ -4,23 +4,38 @@ from crispy_forms.layout import ButtonHolder from crispy_forms.layout import Fieldset from crispy_forms.layout import Layout from crispy_forms.layout import Submit + from django import forms +from django.urls import reverse + +from django.forms import ModelChoiceField + from ctrack.caf.models import CAF +from ctrack.caf.models import DocumentFile class CAFForm(forms.ModelForm): + file = ModelChoiceField( + queryset=DocumentFile.objects.all(), + required=False, + help_text="Please select an existing File. <a href='/caf/file/documentfile/create' target='_blank'>Create new File</a>" # TODO this URL does not exist + ) + class Meta: model = CAF - fields = ["owner", "essential_system"] + fields = ["owner", "essential_system", "file"] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + cancel_redirect = reverse('caf:caf_list') # TODO this URL doesn't exist + self.helper = FormHelper(self) self.helper.form_class = "form-group" self.helper.form_method = "post" self.helper.layout = Layout( - Fieldset("Create/Edit CAF", "owner", "essential_system"), + Fieldset("Create/Edit CAF", "owner", "essential_system", "file"), ButtonHolder(Submit("submit", "Submit"), Button("cancel", "Cancel")), ) + diff --git a/ctrack/caf/migrations/0002_auto_20200207_1622.py b/ctrack/caf/migrations/0002_auto_20200207_1622.py new file mode 100644 index 0000000..2d4575b --- /dev/null +++ b/ctrack/caf/migrations/0002_auto_20200207_1622.py @@ -0,0 +1,19 @@ +# Generated by Django 2.2.9 on 2020-02-07 16:22 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('caf', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='caf', + name='file', + field=models.ForeignKey(blank=True, on_delete=django.db.models.deletion.CASCADE, to='caf.DocumentFile'), + ), + ] diff --git a/ctrack/caf/models.py b/ctrack/caf/models.py index 53faabf..6350871 100644 --- a/ctrack/caf/models.py +++ b/ctrack/caf/models.py @@ -49,7 +49,7 @@ class CAF(models.Model): owner = models.ForeignKey(Organisation, on_delete=models.CASCADE) essential_system = models.CharField(max_length=255, blank=True) triage_ranking = models.ForeignKey(Ranking, on_delete=models.CASCADE) - file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE) + file = models.ForeignKey(DocumentFile, on_delete=models.CASCADE, blank=True) def __str__(self): if not self.essential_system: diff --git a/ctrack/caf/urls.py b/ctrack/caf/urls.py index e819ef7..0f42a40 100644 --- a/ctrack/caf/urls.py +++ b/ctrack/caf/urls.py @@ -1,9 +1,10 @@ from django.urls import path -from ctrack.caf.views import CreateCAF +from ctrack.caf.views import CreateCAF, ListCAF app_name = "caf" urlpatterns = [ - path("", view=CreateCAF.as_view(), name="create") + path("", view=CreateCAF.as_view(), name="create"), + path("", view=ListCAF.as_view(), name="caf_list"), ] diff --git a/ctrack/caf/views.py b/ctrack/caf/views.py index f344aa7..d20b503 100644 --- a/ctrack/caf/views.py +++ b/ctrack/caf/views.py @@ -1,4 +1,4 @@ -from django.views.generic import CreateView +from django.views.generic import CreateView, ListView from ctrack.caf.forms import CAFForm @@ -11,3 +11,8 @@ class CreateCAF(CreateView): context = super().get_context_data(**kwargs) context['form'] = self.form_class return context + + +class ListCAF(ListView): + pass + |