diff --git a/pyconbalkan/news/admin.py b/pyconbalkan/news/admin.py index 313fd620..1393db2b 100644 --- a/pyconbalkan/news/admin.py +++ b/pyconbalkan/news/admin.py @@ -1,10 +1,11 @@ from django.contrib import admin from markdownx.admin import MarkdownxModelAdmin +from pyconbalkan.conference.abstractions import ConferenceAbstractAdmin from pyconbalkan.news.models import Post -class PostAdmin(MarkdownxModelAdmin): +class PostAdmin(ConferenceAbstractAdmin, MarkdownxModelAdmin): class Meta: model = Post diff --git a/pyconbalkan/news/migrations/0008_post_conference.py b/pyconbalkan/news/migrations/0008_post_conference.py new file mode 100644 index 00000000..5ea07730 --- /dev/null +++ b/pyconbalkan/news/migrations/0008_post_conference.py @@ -0,0 +1,21 @@ +# Generated by Django 2.1.7 on 2019-03-03 16:55 + +from django.db import migrations, models +import django.db.models.deletion +import pyconbalkan.conference.abstractions + + +class Migration(migrations.Migration): + + dependencies = [ + ('conference', '0007_auto_20190227_0738'), + ('news', '0007_auto_20180801_2233'), + ] + + operations = [ + migrations.AddField( + model_name='post', + name='conference', + field=models.ForeignKey(default=pyconbalkan.conference.abstractions._get_default_conference, on_delete=django.db.models.deletion.CASCADE, to='conference.Conference'), + ), + ] diff --git a/pyconbalkan/news/models.py b/pyconbalkan/news/models.py index 958010eb..5e52d847 100644 --- a/pyconbalkan/news/models.py +++ b/pyconbalkan/news/models.py @@ -3,10 +3,11 @@ from markdownx.models import MarkdownxField from taggit.managers import TaggableManager +from pyconbalkan.conference.abstractions import AbstractConference from pyconbalkan.core.models import ActiveModel -class Post(ActiveModel): +class Post(ActiveModel, AbstractConference): author = models.ForeignKey('auth.User', on_delete=models.CASCADE) title = models.CharField(max_length=200) text = MarkdownxField() diff --git a/pyconbalkan/news/views.py b/pyconbalkan/news/views.py index 48a99c0f..cc3d5189 100644 --- a/pyconbalkan/news/views.py +++ b/pyconbalkan/news/views.py @@ -14,11 +14,11 @@ class PostViewSet(viewsets.ModelViewSet): def news_view(request): - posts = Post.objects.filter(active=True, published_date__lte=timezone.now()) - context = { - 'news': posts, - } - return render(request, 'news.html', context) + posts = Post.objects.filter( + active=True, published_date__lte=timezone.now(), conference=request.conference + ) + context = {"news": posts} + return render(request, "news.html", context) def post_detail(request, slug): @@ -29,12 +29,9 @@ def post_detail(request, slug): keywords=post.keywords.names(), image=post.image.url, extra_props={ - 'viewport': 'width=device-width, initial-scale=1.0, minimum-scale=1.0' - } + "viewport": "width=device-width, initial-scale=1.0, minimum-scale=1.0" + }, ) - context = { - 'post': post, - 'meta': meta, - } - return render(request, 'post.html', context) \ No newline at end of file + context = {"post": post, "meta": meta} + return render(request, "post.html", context)