Commit 2e106e8a authored by Barnabás Czémán's avatar Barnabás Czémán
Browse files

Refactoring

parent 76dc8159
...@@ -37,7 +37,7 @@ INSTALLED_APPS = [ ...@@ -37,7 +37,7 @@ INSTALLED_APPS = [
'django.contrib.sessions', 'django.contrib.sessions',
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'pityu' 'web'
] ]
MIDDLEWARE_CLASSES = [ MIDDLEWARE_CLASSES = [
...@@ -56,8 +56,7 @@ ROOT_URLCONF = 'entries.urls' ...@@ -56,8 +56,7 @@ ROOT_URLCONF = 'entries.urls'
TEMPLATES = [ TEMPLATES = [
{ {
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')] 'DIRS': [os.path.join(BASE_DIR, 'templates')],
,
'APP_DIRS': True, 'APP_DIRS': True,
'OPTIONS': { 'OPTIONS': {
'context_processors': [ 'context_processors': [
......
from django.conf.urls import url, include from django.conf.urls import url, include
from django.contrib import admin from django.contrib import admin
from pityu.urls import url_patterns from web.urls import url_patterns
urlpatterns = [ urlpatterns = [
url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls),
......
from django.contrib import admin
from .models import Entry
class EntryAdmin(admin.ModelAdmin):
pass
admin.site.register(Entry, EntryAdmin)
from django.apps import AppConfig
class PityuConfig(AppConfig):
name = 'pityu'
# -*- coding: utf-8 -*-
# Generated by Django 1.9 on 2016-04-06 17:37
from __future__ import unicode_literals
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Entry',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=60)),
('description', models.TextField(blank=True)),
('url', models.URLField(blank=True)),
('logo', models.ImageField(blank=True, upload_to='')),
('added_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
from django.db import models
from django.contrib.auth.models import User
class Entry(models.Model):
title = models.CharField(max_length=60)
description = models.TextField(blank=True)
url = models.URLField(blank=True)
logo = models.ImageField(blank=True)
added_by = models.ForeignKey(User)
def __str__(self):
return self.title
# -*- encoding: utf-8 -*-
from django.conf.urls import url
from .views import home, EntryCreateView
url_patterns = [
url(r'^$', home, name='home'),
url(r'^create/$', EntryCreateView.as_view(), name='create_entry'),
]
from django.shortcuts import render
from django.core.urlresolvers import reverse_lazy
from django.views.generic import CreateView
from django.contrib.auth.mixins import LoginRequiredMixin
from .models import Entry
def home(request):
entries = Entry.objects.all()
context = {
'valami': 'Szaki',
'entries': entries
}
return render(request, 'index.html', context)
class EntryCreateView(LoginRequiredMixin, CreateView):
model = Entry
fields = ('title', 'description', 'url', 'logo')
template_name = 'create_entry.html'
success_url = reverse_lazy('home')
def form_valid(self, form):
form.instance.added_by = self.request.user
return super(EntryCreateView, self).form_valid(form)
Supports Markdown
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