Kaydet (Commit) 1d7637c9 authored tarafından Batuhan Taşkaya's avatar Batuhan Taşkaya

extended list

üst 3c979907
......@@ -3,7 +3,7 @@ from django.contrib.auth import get_user_model
from django.contrib.auth.admin import UserAdmin
from social.forms import SocialUserCreationForm, SocialUserChangeForm
from social.models import SocialUser, Post
from social.models import SocialUser, Post, Snippet
class SocialUserAdmin(UserAdmin):
add_form = SocialUserCreationForm
......@@ -13,3 +13,4 @@ class SocialUserAdmin(UserAdmin):
admin.site.register(SocialUser, SocialUserAdmin)
admin.site.register(Post)
admin.site.register(Snippet)
# Generated by Django 2.2.1 on 2019-05-04 15:47
# Generated by Django 2.2.1 on 2019-05-04 17:18
from django.conf import settings
import django.contrib.auth.models
......@@ -44,10 +44,9 @@ class Migration(migrations.Migration):
],
),
migrations.CreateModel(
name='Post',
name='Sharable',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('text', models.TextField(max_length=288)),
('pub_date', models.TimeField(auto_now=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
......@@ -55,4 +54,12 @@ class Migration(migrations.Migration):
'ordering': ['pub_date'],
},
),
migrations.CreateModel(
name='Post',
fields=[
('sharable_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='social.Sharable')),
('text', models.TextField(max_length=288)),
],
bases=('social.sharable',),
),
]
# Generated by Django 2.2.1 on 2019-05-04 17:26
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('social', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Snippet',
fields=[
('sharable_ptr', models.OneToOneField(auto_created=True, on_delete=django.db.models.deletion.CASCADE, parent_link=True, primary_key=True, serialize=False, to='social.Sharable')),
('text', models.TextField()),
],
bases=('social.sharable',),
),
]
......@@ -4,9 +4,8 @@ from django.contrib.auth.models import AbstractUser
class SocialUser(AbstractUser):
pass
class Post(models.Model):
class Sharable(models.Model):
class Meta:
ordering = ['pub_date']
......@@ -15,8 +14,13 @@ class Post(models.Model):
on_delete=models.CASCADE,
)
text = models.TextField(max_length=settings.MAX_POST_LENGTH)
pub_date = models.TimeField(auto_now=True)
def __str__(self):
return f"{self.author}#{self.id}"
return f"{self.__class__.__name__}@{self.author}"
class Post(Sharable):
text = models.TextField(max_length=settings.MAX_POST_LENGTH)
class Snippet(Sharable):
text = models.TextField()
......@@ -3,11 +3,13 @@
<head>
<meta charset="utf-8">
<title>{% block title %}Aspava{% endblock %}</title>
{% block css %}{% endblock %}
</head>
<body>
<main>
{% block content %}
{% endblock %}
</main>
{% block js %}{% endblock %}
</body>
</html>
{% extends 'base.html' %}
{% block title %}Home{% endblock %}
{% block css %}
<link rel="stylesheet" href="https://prismjs.com/themes/prism.css" data-noprefix />
{% endblock %}
{% block content %}
{% if user.is_authenticated %}
Hi {{ user.username }}!
......@@ -15,3 +17,6 @@
<a href="{% url 'login' %}">login</a>
{% endif %}
{% endblock %}
{% block js %}
<script src="https://prismjs.com/prism.js"></script>
{% endblock %}
<div>
<pre>
<code class="language-py">{{ item.text }}</code>
</pre>
</div>
......@@ -2,7 +2,7 @@ from django.contrib.auth.forms import UserCreationForm
from django.urls import reverse_lazy
from django.views.generic import CreateView, ListView
from django.views.generic.base import TemplateView
from social.models import Post
from social.models import Post, Snippet
from operator import or_
from functools import wraps, reduce
......@@ -20,14 +20,13 @@ def ret_or_super(func):
return wrapper
class ExtendedListView(ListView):
@ret_or_super
def get_queryset(self):
queryset = reduce(or_, map(lambda model: model._default_manager.all(), self.models))
return queryset
class Home(ExtendedListView):
models = Post,
models = Post, Snippet
template_name = 'home.html'
context_object_name = 'feed'
......
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