On 7/16/2010 7:28 PM, Sells, Fred wrote:
> I've got a logical record 0f 500 columns that is broken up into about 20
> tables based on an implicit logical grouping of the data.  Most of the
> time this works well and the code is clean; but there are a few use
> cases where I need to get all the equivalent fields for a single record
> from all the tables.  The "select_related()" seems to only follow to the
> "parent" table, while I want to use the parent table to get all the
> related "child" (or sibling to be more precise) columns.  I know I could
> use a for loop and a __dict__.update() to make multiple queries of the
> DB and get the data, or I could write some SQL to select all; but
> neither seem very Pythonic.  
> 
> Is there a clean way to do this in Django?
> 
Maybe you could define a view in SQL (using CREATE VIEW AS <select
statement>), joining all the necessary tables, that Django could then
treat as a (preferably read-only) model to give you access to the joined
tables?

If you are competent enough to write a special-purpose Manager to load
the columns lazily when the code requested them.

regards
 Steve
> 
> 
> My models.py contains this code (snipped for brevity)
> 
> class Assessment(models.Model):
>     facility    = models.ForeignKey(Facility, default='MZ')
>     resid    = models.CharField(max_length=7, default='MZ00001')
>     status   = models.IntegerField(default=0)
> 
> class MDSSection(models.Model):
>     assessment     = models.OneToOneField(Assessment, primary_key=True)
> 
>     class Meta:
>         abstract= True
> 
> class A(MDSSection):
>     A0100A    = models.CharField(max_length=10, help_text='''Text      :
> Facility National Provider Identifier (NPI)''') 
>     A0100B    = models.CharField(max_length=12, help_text='''Text      :
> Facility CMS Certification Number (CCN)''') 
>     A0100C    = models.CharField(max_length=15, help_text='''Text      :
> State provider number''')
> 
> class B(MDSSection):
>     B0100     = models.CharField(max_length= 1, help_text='''Code      :
> Comatose''') 
>     B0200     = models.CharField(max_length= 1, help_text='''Code      :
> Hearing''') 
>     B0300     = models.CharField(max_length= 1, help_text='''Code      :
> Hearing aid''')
> 
> ...
> 


-- 
Steve Holden           +1 571 484 6266   +1 800 494 3119
DjangoCon US September 7-9, 2010    http://djangocon.us/
See Python Video!       http://python.mirocommunity.org/
Holden Web LLC                 http://www.holdenweb.com/

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

Reply via email to