Commit 64dd818f authored by onny's avatar onny
Browse files

added artist endpoint

parent 69eefc27
......@@ -16,15 +16,15 @@ Including another URLconf
from django.conf.urls import url, include
from django.contrib import admin
from rest_framework import routers
from joblist.views import job_list, JobsViewSet
from joblist.views import job_list, JobsViewSet, ArtistViewSet
# Routers provide an easy way of automatically determining the URL conf.
router = routers.DefaultRouter()
router.register(r'jobs', JobsViewSet)
router.register(r'artist', ArtistViewSet)
urlpatterns = [
url(r'^admin/', admin.site.urls),
url(r'^$', job_list),
url(r'^api/', include(router.urls)),
]
from django.contrib import admin
from .models import JobList
from .models import JobList, Artist
admin.site.register(JobList)
admin.site.register(Artist)
# Register your models here.
......@@ -3,7 +3,7 @@ from __future__ import unicode_literals
from django.db import models
class Artist(models.Model):
name = models.CharField(max_length=100)
artistname = models.CharField(max_length=100)
class Project(models.Model):
artist = models.ForeignKey(Artist, on_delete=models.CASCADE)
......
from .models import JobList
from .models import JobList, Artist
from rest_framework import serializers
class JobsSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = JobList
fields = ('id', 'jobtitle', 'jobdescription', 'postdate')
class ArtistSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Artist
fields = ('id', 'artistname')
from django.template.response import TemplateResponse
from django.http import HttpResponse
from .models import JobList
from .models import JobList, Artist
from rest_framework import viewsets
from .serializers import JobsSerializer
from .serializers import JobsSerializer, ArtistSerializer
# Create your views here.
def job_list(request):
......@@ -12,9 +12,23 @@ def job_list(request):
html = TemplateResponse(request, 'joblist.html', context)
return HttpResponse(html.render())
def artist_list(request):
context = {}
context['artist'] = Artist.objects.all()
html = TemplateResponse(request, 'artist.html', context)
return HttpResponse(html.render())
class JobsViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows jobs to be viewed or edited.
"""
queryset = JobList.objects.all()
serializer_class = JobsSerializer
class ArtistViewSet(viewsets.ModelViewSet):
"""
API endpoint that allows jobs to be viewed or edited.
"""
queryset = Artist.objects.all()
serializer_class = ArtistSerializer
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
body {
margin-top: 70px;
}
.navbar-default {
background-color: #0C4B33 !important;
background-image: none !important;
}
.navbar-header {
width:100%;
}
.navtitle {
margin: auto;
display: inline-block;
}
.navbar-brand {
color: white !important;
display: inline;
}
.navimage {
max-height: 40px;
float: left;
padding: 0;
margin: 5px;
display: inline;
}
.job {
background-color: #44B78B;
margin: 10px auto;
padding: 10px 25px;
border-radius: 10px;
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
axios.defaults.xsrfCookieName = 'csrftoken'
axios.defaults.xsrfHeaderName = "X-CSRFTOKEN"
var demo = new Vue({
el: '#app',
data: {
'apptitle': 'saaiArt',
'jobs': [],
'jobtitle': '',
'jobdescription': '',
'artistname': '',
'projectname': ''
},
delimiters: ["[[","]]"],
methods: {
addJob: function () {
var newJob = {
jobtitle: this.jobtitle.trim(),
jobdescription: this.jobdescription.trim()
};
axios
.post('http://127.0.0.1:8000/api/jobs/', newJob)
},
removeJob: function (index) {
axios
.delete('http://127.0.0.1:8000/api/jobs/'.concat(this.jobs[index].id));
this.jobs.splice(index, 1);
}
},
mounted: function()
{
axios
.get('http://127.0.0.1:8000/api/jobs/')
.then(response => (this.jobs = response.data))
}
});
......@@ -3,38 +3,26 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="{% static 'css/jobboard.css' %}">
<title>Django Vue.JS Job Board</title>
<link rel="stylesheet" href="{% static 'css/main.css' %}">
<title>saaiArt</title>
</head>
<body>
<div id="app">
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container">
<div class="navbar-header text-center">
<div class="navtitle">
<span class="navbar-brand" href="/">[[ apptitle ]]</span>
</div>
</div>
</div>
</nav>
<h1 href="/">[[ apptitle ]]</h1>
{% block jobs %}
{% endblock %}
</div>
<script src="{% static 'js/jquery-1.11.3.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
</div>
<!-- Vue.JS -->
<!-- <script type="text/javascript" src="{% static 'js/vue-2.6.10.min.js' %}"></script> -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script type="text/javascript" src="{% static 'js/vue-resource-1.5.1.min.js' %}"></script>
<script type="text/javascript" src="{% static 'vuejs/djangovue.js' %}"></script>
<script type="text/javascript" src="{% static 'js/main.js' %}"></script>
</body>
</html>
......@@ -4,20 +4,38 @@
<div class="container">
<h2>Create an artist</h2>
<form class="form-group col-sm-8 form-horizontal">
<label class="form-label" for="artistname">Job Title</label>
<input class="form-control" id="artistname" v-model="artistname">
<label class="form-label" for="name">Name</label>
<input class="form-control" id="name" v-model="artistname">
<br>
<button class="btn" v-on:click="addArtist()">Submit</button>
</form>
<h2>Create a project</h2>
<form class="form-group col-sm-8 form-horizontal">
<label class="form-label" for="projectname">Project name</label>
<input class="form-control" id="projectname" v-model="artistname">
<label class="form-label" for="project">Belongs to artist</label>
<select id="artistid" name="artistid">
<option value="" selected>Please choose</option>
</select>
<br>
<label class="form-label" for="name">Name</label>
<input class="form-control" id="name" v-model="projectname">
<br>
<button class="btn" v-on:click="addProject()">Submit</button>
</form>
<h2>Add an entry</h2>
<form class="form-group col-sm-8 form-horizontal">
<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>
</form>
<h2>Post a Job</h2>
<form class="form-group col-sm-8 form-horizontal">
<label class="form-label" for="title">Job Title</label>
......
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