Commit cd26c412 authored by onny's avatar onny

add entry table

parent 24947cda
......@@ -16,12 +16,14 @@ Including another URLconf
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework import routers
from openart.views import index_page, add_page, artists_page, projects_page, entries_page, ArtistViewSet, ProjectViewSet
from openart.views import index_page, add_page, artists_page, projects_page, entries_page
from openart.views import ArtistViewSet, ProjectViewSet, EntryViewSet
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'artist', ArtistViewSet)
router.register(r'project', ProjectViewSet)
router.register(r'entry', EntryViewSet)
urlpatterns = [
url(r'^admin/', admin.site.urls),
......
......@@ -27,4 +27,12 @@ class ProjectForm(forms.ModelForm):
class EntryForm(forms.ModelForm):
class Meta:
model = Entry
fields = ['signatory', 'description', 'filename', 'dimension', 'visibility', 'type'] # FIXME: project
fields = ['project', 'signatory', 'description', 'dimension', 'visibility', 'type']
widgets = {
'project': forms.Select(attrs={'v-model': 'project.id'}),
'signatory': forms.TextInput(attrs={'v-model': 'entry.signatory'}),
'description': forms.TextInput(attrs={'v-model': 'entry.description'}),
'dimension': forms.TextInput(attrs={'v-model': 'entry.dimension'}),
'visibility': forms.CheckboxInput(attrs={'v-model': 'entry.visibility'}),
'type': forms.Select(attrs={'v-model': 'entry.type'})
}
......@@ -22,7 +22,6 @@ class Entry(models.Model):
project = models.ForeignKey(Project, on_delete=models.CASCADE)
signatory = models.CharField(max_length=100)
description = models.CharField(max_length=100)
filename = models.CharField(max_length=100)
dimension = models.CharField(max_length=100)
visibility = models.BooleanField(default=False)
......
from .models import Artist, Project
from .models import Artist, Project, Entry
from rest_framework import serializers
class ArtistSerializer(serializers.ModelSerializer):
......@@ -33,3 +33,16 @@ class ProjectReadSerializer(serializers.ModelSerializer):
class Meta:
model = Project
fields = ('id', 'artist', 'name', 'slug')
class EntrySerializer(serializers.ModelSerializer):
class Meta:
model = Entry
fields = ('id', 'project', 'signatory', 'description', 'dimension', 'visibility', 'type')
class EntryReadSerializer(serializers.ModelSerializer):
project = ProjectSerializer(many=False, read_only=True)
class Meta:
model = Entry
fields = ('id', 'project', 'signatory', 'description', 'dimension', 'visibility', 'type')
from django.template.response import TemplateResponse
from django.http import HttpResponse
from .models import Artist, Project
from .models import Artist, Project, Entry
from rest_framework import viewsets
from .serializers import ArtistSerializer, ProjectSerializer, ProjectReadSerializer
from .serializers import ArtistSerializer, ProjectSerializer, ProjectReadSerializer, EntrySerializer, EntryReadSerializer
from .forms import ArtistForm, ProjectForm, EntryForm
def index_page(request):
......@@ -35,9 +35,9 @@ def projects_page(request):
def entries_page(request):
context = {}
context['artist'] = Artist.objects.all()
context['entry'] = Entry.objects.all()
html = TemplateResponse(request, 'artists.html', context)
html = TemplateResponse(request, 'entries.html', context)
return HttpResponse(html.render())
class ArtistViewSet(viewsets.ModelViewSet):
......@@ -54,3 +54,11 @@ class ProjectViewSet(viewsets.ModelViewSet):
if self.request.method in ['GET']:
return ProjectReadSerializer
return ProjectSerializer
class EntryViewSet(viewsets.ModelViewSet):
queryset = Entry.objects.all()
def get_serializer_class(self):
if self.request.method in ['GET']:
return EntryReadSerializer
return EntrySerializer
......@@ -7,9 +7,7 @@ var demo = new Vue({
'apptitle': 'openArt',
'artist': [],
'project': [],
'name': '',
'artistid': '',
'signatory': ''
'entry': []
},
delimiters: ["[[","]]"],
methods: {
......@@ -31,6 +29,18 @@ var demo = new Vue({
axios
.post('http://127.0.0.1:8000/api/project/', newProject);
},
addEntry: function () {
var newEntry = {
project: this.project.id,
signatory: this.entry.signatory.trim(),
description: this.entry.description.trim(),
dimension: this.entry.dimension.trim(),
visibility: this.entry.visibility,
type: this.entry.type
};
axios
.post('http://127.0.0.1:8000/api/entry/', newEntry);
},
removeArtist: function (index) {
axios
.delete('http://127.0.0.1:8000/api/artist/'.concat(this.artist[index].id));
......@@ -41,6 +51,11 @@ var demo = new Vue({
axios
.delete('http://127.0.0.1:8000/api/project/'.concat(this.project[index].id));
this.project.splice(index, 1);
},
removeEntry: function (index) {
axios
.delete('http://127.0.0.1:8000/api/entry/'.concat(this.entry[index].id));
this.entry.splice(index, 1);
}
},
mounted: function()
......@@ -57,6 +72,11 @@ var demo = new Vue({
.get('http://127.0.0.1:8000/api/project/')
.then(response => (this.project = response.data));
break;
case "/entries/":
axios
.get('http://127.0.0.1:8000/api/entry/')
.then(response => (this.entry = response.data));
break;
};
}
});
......@@ -16,33 +16,17 @@
<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>
</select>
<br>
<label class="form-label" for="name">Name</label>
<input class="form-control" id="name" v-model="project.name"> -->
<br>
<button type="submit" v-on:click="addProject()">Submit</button>
</form>
<h2>Add an entry</h2>
<form class="form-group col-sm-8 form-horizontal">
<form v-on:submit.preven>
<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>
</select>
<br>
<label class="form-label" for="signatory">Signatory</label>
<input class="form-control" id="signatory" v-model="signatory">
<br>
<button class="btn" v-on:click="addEntry()">Submit</button>
<button type="submit" v-on:click="addEntry()">Submit</button>
</form>
</div>
{% endblock %}
......@@ -3,12 +3,13 @@
{% block jobs %}
<h2>Entries</h2>
<div class="flex-container">
<p v-if="artist.length == 0">Sorry, no jobs currently available</p>
<div v-for="(artist, index) in artist" class="artist">
<p v-if="entry.length == 0">Sorry, no entires currently available</p>
<div v-for="(entry, index) in entry" class="artist">
<div class="col-sm-12">
<img src="https://uploads.wikiart.org/Content/images/ARTIST-480x600.jpg" width=100px>
<h3>[[ artist.artistname ]]</h3>
<button class="btn" v-on:click="removeArtist([[ index ]])">Delete</button>
<br><b>[[ entry.signatory ]]</b><br>
of [[ entry.project.name ]]<br>
<button class="btn" v-on:click="removeEntry([[ index ]])">Delete</button>
</div>
</div>
</div>
......
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