Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Dynamic tables?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  1 message - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
joshuakarjala  
View profile  
 More options Nov 12, 2:49 pm
From: joshuakarjala <joshuakarj...@gmail.com>
Date: Thu, 12 Nov 2009 11:49:04 -0800 (PST)
Local: Thurs, Nov 12 2009 2:49 pm
Subject: Dynamic tables?
Hi,

I'm trying to build a small app to create size charts like:
http://www.steepplanet.com/prodimages/Giordana/size_chart.jpg

So each size chart need to have it's own number of necessary columns
and rows. And each size chart can be assigned to any amount of
brands.

So my models.py looks like

from django.db import models
import django_tables as tables
from sizechart.translation import TranslationModel

class Brand(models.Model):
        name = models.CharField(max_length=255)
        slug = models.SlugField(help_text='Automatically built from name.')

        class Meta:
                ordering = ["name"]
                verbose_name_plural = "Brands"

        def __unicode__(self):
                return self.name

class SizeChart(TranslationModel):
        brands = models.ManyToManyField("sizechart.Brand", blank=True, )
        name = models.CharField(max_length=255)

        class Meta:
                ordering = ["name"]
                verbose_name_plural = "Size charts"

        class Translation:
                fields = ['name', ]

        def __unicode__(self):
                return self.name

class Row(models.Model):
        sizechart = models.ForeignKey("sizechart.SizeChart")

        def __unicode__(self):
                return u"Row"

class Column(TranslationModel):
        """(Column description)"""
        row = models.ForeignKey("sizechart.Row")
        value = models.CharField(blank=True, max_length=100)

        class Translation:
                field = ['value', ]

        def __unicode__(self):
                return u"Column"

and admin.py

from django.contrib import admin
from sizechart.models import Brand, SizeChart, Row, Column

class SizeChartInline(admin.TabularInline):
        model = SizeChart.brands.through
        extra = 1
        max_num = 10

class ColumnInline(admin.StackedInline):
        model = Column
        extra = 1
        max_num = 10
        classes = ('collapse-open',)
        allow_add = True

class RowInline(admin.StackedInline):
        model = Row
        extra = 1
        max_num = 10
        classes = ('collapse-open',)
        allow_add = True
        inlines = (ColumnInline)

class BrandAdmin(admin.ModelAdmin):
        list_display = ('name', 'slug', )
        search_fields = ('name', 'slug', )
        prepopulated_fields = {"slug" : ('name',)}
        inlines = (SizeChartInline, )

class SizeChartAdmin(admin.ModelAdmin):
        list_display = ('name', )
        search_fields = ('name', )
        inlines = (RowInline, )

admin.site.register(Brand, BrandAdmin)
admin.site.register(SizeChart, SizeChartAdmin)

////////////////////

But the ColumnInline doesn't seem to register.

Does anyone have a better idea of how to implement this?


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google