Skip to content

Commit

Permalink
updated filters and relations (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
MathyouMB authored Feb 20, 2021
1 parent 4a1256a commit ba6e01a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
3 changes: 2 additions & 1 deletion resources/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
@admin.register(Resource)
class CustomerResource(admin.ModelAdmin):
list_display = ("title", "found_date", "status", "order", "resource_page_section")

list_filter =("resource_page_section", "status")
@admin.register(ResourcePage)
class CustomerResourcePage(admin.ModelAdmin):
list_display = ["title"]
@admin.register(ResourcePageSection)
class CustomerResourceSection(admin.ModelAdmin):
list_display = ("title", "resource_page", "order", "status")
list_filter =("resource_page", "status")
18 changes: 18 additions & 0 deletions resources/migrations/0014_resourcepagesection_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.4 on 2021-02-20 09:31

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('resources', '0013_resourcepagesection_status'),
]

operations = [
migrations.AddField(
model_name='resourcepagesection',
name='url',
field=models.TextField(blank=True, null=True),
),
]
6 changes: 4 additions & 2 deletions resources/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ class ResourcePage(models.Model):
description = models.TextField(null=True, blank=True)

def public_sections(self):
return ResourcePageSection.objects.filter(status='p').order_by('order')
return self.resource_page_sections.filter(status='p').order_by('order')


def __str__(self):
return self.title

class ResourcePageSection(models.Model):
title = models.CharField(max_length=75)
description = models.TextField(null=True, blank=True)
url = models.TextField(null=True, blank=True)
order = models.DecimalField(max_digits=10, decimal_places=2, default=0.0)
status = models.CharField(choices=(
('p', "public"),
Expand All @@ -38,7 +40,7 @@ class ResourcePageSection(models.Model):
resource_page = models.ForeignKey(ResourcePage, related_name='resource_page_sections', on_delete=models.CASCADE, blank=True, null=True)

def public_resources(self):
return Resource.objects.filter(status='p').order_by('order')
return self.resources.filter(status='p').order_by('order')

def __str__(self):
return self.title
Expand Down

0 comments on commit ba6e01a

Please sign in to comment.