From 8c2c532ce79901a64908e2a6ff9c5ff1755d3ee8 Mon Sep 17 00:00:00 2001 From: Sanjay Bhangar Date: Sat, 10 Jun 2017 16:37:32 +0530 Subject: [PATCH] add parents as inline to contents --- content/admin.py | 5 +++++ content/models.py | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/content/admin.py b/content/admin.py index 7f6f4e9..46c6a11 100644 --- a/content/admin.py +++ b/content/admin.py @@ -6,6 +6,10 @@ from django.contrib import admin # Register your models here. from models import * + +class ContentParentsInline(admin.TabularInline): + model = ContentContent + fk_name = 'contentid1' ''' class SubdomainInline(admin.StackedInline): model = Subdomain @@ -22,6 +26,7 @@ class ContentAdmin(admin.ModelAdmin): list_display = ('__unicode__', 'datestart', 'type') list_filter = ['datestart', 'type'] search_fields = ['title', 'body', 'header'] + inlines = [ContentParentsInline] # inlines = [SubdomainInline, DomainAliasInline] # list_display = ('url', 'server', 'manage_nameserver', 'domain_registrar', 'email', 'is_active') diff --git a/content/models.py b/content/models.py index f66f51d..da421f9 100644 --- a/content/models.py +++ b/content/models.py @@ -75,7 +75,7 @@ class Content(models.Model): view = models.ForeignKey("Views", null=True, blank=True, db_column="view") place = models.CharField(max_length=255, null=True, blank=True) parentid = models.ForeignKey("Content", null=True, db_column='parentID', blank=True, limit_choices_to={'type_id': 3}, related_name="please_run") # Field name made lowercase. - content_related = models.ManyToManyField('Content', through='ContentContent', related_name= "run_run_run") + parents = models.ManyToManyField('Content', through='ContentContent', related_name= "children") def __unicode__(self): return self.title @@ -87,8 +87,11 @@ class Content(models.Model): class ContentContent(models.Model): - contentid1 = models.ForeignKey("content", db_column='contentID1', related_name="from_content") # Field name made lowercase. - contentid2 = models.ForeignKey("content", db_column='contentID2', related_name="to_content") # Field name made lowercase. + contentid1 = models.ForeignKey("content", db_column='contentID1', related_name="child") # Field name made lowercase. + contentid2 = models.ForeignKey("content", db_column='contentID2', related_name="parent") # Field name made lowercase. + + def __unicode__(self): + return "%s is child of %s" % (self.contentid1.title, self.contentid2.title,) class Meta: managed = False