Commit 7c7cea0a authored by onny's avatar onny
Browse files

added several forms

parent afa3c6ee
from django import forms
#from django.forms import ModelForm, HiddenInput
from .models import Artist, Project, Entry
#alphanumeric = RegexValidator(r'^[0-9a-zA-Z]*$', 'Only alphanumeric characters are allowed.')
class ArtistForm(forms.ModelForm):
class Meta:
model = Artist
fields = ['name',]
widgets = {
'name': forms.TextInput(attrs={'v-model': 'artist.name'})
}
class ProjectForm(forms.ModelForm):
class Meta:
model = Project
fields = ['artist', 'name', 'city', 'datefrom', 'dateto']
class EntryForm(forms.ModelForm):
class Meta:
model = Entry
fields = ['signatory', 'description', 'filename', 'dimension', 'visibility', 'type'] # FIXME: project
......@@ -3,14 +3,14 @@ from __future__ import unicode_literals
from django.db import models
class Artist(models.Model):
name = models.CharField(max_length=100)
name = models.CharField(max_length=100, blank=False)
def __str__(self):
return self.name
class Project(models.Model):
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
name = models.CharField(max_length=100, blank=False)
city = models.CharField(max_length=100)
datefrom = models.DateField()
dateto = models.DateField()
......
......@@ -3,6 +3,7 @@ from django.http import HttpResponse
from .models import Artist, Project
from rest_framework import viewsets
from .serializers import ArtistSerializer, ProjectSerializer, ProjectReadSerializer
from .forms import ArtistForm, ProjectForm, EntryForm
def index_page(request):
html = TemplateResponse(request, 'index.html')
......@@ -11,6 +12,9 @@ def index_page(request):
def add_page(request):
context = {}
context['artist'] = Artist.objects.all()
context['artist_form'] = ArtistForm
context['project_form'] = ProjectForm
context['entry_form'] = EntryForm
html = TemplateResponse(request, 'add.html', context)
return HttpResponse(html.render())
......
......@@ -3,15 +3,20 @@
{% block jobs %}
<div class="main">
<h2>Create an artist</h2>
<form v-on:submit.prevent class="form-group col-sm-8 form-horizontal">
<label class="form-label" for="name">Name</label>
<input class="form-control" id="name" v-model="artist.name">
<form v-on:submit.prevent>
<table>
{{ artist_form.as_table }}
</table>
<br>
<button class="btn" v-on:click="addArtist()">Submit</button>
</form>
<h2>Create a project</h2>
<form v-on:submit.prevent class="form-group col-sm-8 form-horizontal">
<table>
{{ project_form.as_table }}
</table>
<label class="form-label" for="project">Belongs to artist</label>
<select id="artist" name="artist" v-model="artist.id">
<option v-for="(artist, index) in artist" :value="artist.id" selected>[[ artist.name ]]</option>
......@@ -25,6 +30,9 @@
<h2>Add an entry</h2>
<form class="form-group col-sm-8 form-horizontal">
<table>
{{ entry_form.as_table }}
</table>
<label class="form-label" for="project">Belongs to project</label>
<select id="projectid" name="projectid">
<option value="" selected>Please choose</option>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment