Monday, December 31, 2012

Re: alternate way for nested inline in django admin

it no posible nested inline in django !!


On Sat, Dec 29, 2012 at 10:36 AM, Nikhil Verma <varma.nikhil22@gmail.com> wrote:
Hi All

Can somebody explain me the workaround for this ticket 9025. I want to nested inlines in my django admin
explained below.

Thanks in advance

On Fri, Dec 28, 2012 at 10:54 PM, Nikhil Verma <varma.nikhil22@gmail.com> wrote:
Hi Guys

Here are my models :-

class Blog(models.Model):
    """
    This model represents information that is stored about a blog.
    """
   
    seo_tag = models.CharField(max_length=100)
    title = models.CharField(max_length=100, unique=True)
    description = models.TextField(verbose_name="content")
    meta_description = models.TextField(max_length=5000)
    image = models.ImageField(upload_to="blogs/images/", blank=True)
    video = models.FileField(upload_to="blogs/videos/", blank=True)
     -------- and so on ------------

class BlogSidebarTitle(models.Model):
    """
    Describes the related title and sublinks inside
    the custom sidebar
    """
   
    associated_blog = models.ForeignKey(Blog)
    title = models.CharField(max_length=255,null=True,blank=True)
    title_sequence = models.IntegerField(null=True,blank=True)
   
    def __unicode__(self):
        return self.title
   
#-------------------------------------------------------------------------------
class BlogSidebarSubtitle(models.Model):
    """
    Subtitle within the sidebar
    """
    associated_blog = models.ForeignKey(Blog)
    title = models.ForeignKey(BlogSidebarTitle)
    sublink_title = models.CharField(max_length=255,null=True,blank=True)
    sublink_title_sequence = models.IntegerField(null=True,blank=True)
    sublink_title_url = models.URLField(blank=True,null=True)
   
    def __unicode__(self):
        return self.sublink_title



Now i want that if i go to add blog page in admin i can add multiple subtitle  for a single title

Like this :-

Add blog Page :-
After blog fields in admin
# I want that it should be Tabularline
Fieldset Blog Sidebar title
            Title                                 Title sequence
            # after this is should be having
           Sublink_title                     sublink_title_sequence     sublink _title_url    
           # then is hould be able to add more subtitle to single title
           + Add another Sublink title

So i wrote the admin like this :-

#-------------------------------------------------------------------------------
class BlogSidebarSubtitleInline(admin.TabularInline):
    """
    """
   
    models = BlogSidebarSubtitle
    extra = 1
#-------------------------------------------------------------------------------
class BlogSidebarTitleInline(admin.TabularInline):
    """
    Making it appear on blog screen
    """
   
    model = BlogSidebarTitle
    extra = 1
#-------------------------------------------------------------------------------
class BlogSidebarTitleAdmin(admin.ModelAdmin):
    inlines = [BlogSidebarSubtitleInline,]
    extra = 1

class BlogAdmin(admin.ModelAdmin):
    """
    Finally the layout of it.
    """
   
    # For tags
    filter_horizontal = ('tags',)
   
    # Calling the Editor
    class Media:
        js = (
              '/static/tinymce/jscripts/tiny_mce/tiny_mce.js',
              '/static/js/textarea.js',
              )
    # Finally diving the page into fieldsets
    fieldsets = [
        ('Blog',{'fields': ['seo_tag', 'title','meta_description', 'description',
                            'category', 'image','video', 'save_as_draft',
                            'featured', 'tags']})]
    #readonly_fields = ['seo_tag',]
   
    inlines = [BlogSidebarButtonsInline, BlogSidebarTitleInline]


But still the BlogSidebarSubtitle class fields are not appearing in admin and i am not able to have nested inlines.

Can anybody tell the appropriate way to do this and if not where i am doing wrong in the above code.

Thanks  .
--
Regards
Nikhil Verma
+91-958-273-3156



--
Regards
Nikhil Verma
+91-958-273-3156

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment