Changes between Version 5 and Version 6 of DescriptorFields


Ignore:
Timestamp:
12/13/2005 11:45:04 AM (10 years ago)
Author:
anonymous
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DescriptorFields

    v5 v6  
     1==Fields as Descriptors==
     2
    13In this proposal, fields would become descriptors.
    2 
     4 
    35This means
    46
     
    1214   - the simple data instance from the private dict that was fetched from the db.
    1315   - a lazily computed value, eg a BLOB field which would be fetched from the db on first access, not at initial load time, or a ForeignKey relationship that hasn't been loaded yet.
     16   For a ForeignKey,
     17
     18   {{{
     19     article.get_reporter()
     20     article.reporter_id
     21   }}}
     22
     23   would change to:
     24   {{{
     25     article.reporter
     26     article.reporter.id
     27   }}}
    1428
    1529 * ForeignKeys and other related fields would place another descriptor on the related class.
     
    1832   
    1933   This would also support other methods in favour of the get_related_list things.
    20 
    21    So:
     34   
     35   Other end of ForeignKey relationship:
     36   
    2237   {{{
    2338    reporter.get_article_list()
     
    4459   - .add would add a new instance of the related class to the collection.
    4560     This would register a callback so that it would be written to the db when .save() is called on the parent object.
    46    
     61
     62   ManyToMany examples: (from http://www.djangoproject.com/documentation/models/many_to_many/ )
     63   {{{
     64       a1.set_publications([p1.id])
     65   }}}     
     66   goes to 
     67   {{{    a1.publication_set.clear()
     68          a1.publication_set.add(p1)
     69   }}}
     70   This looks a bit odd because of the clear call . In reality, most of the time you don't want to replace a whole set of many-to-manys, so the new api is more convenient than the old one. The methods are precisely those of a Python 2.4 built in set.
     71   ----
     72   {{{
     73          a2.set_publications([p1.id])
     74          a2.set_publications([p1.id, p2.id])
     75   }}}
     76   goes to
     77   {{{ 
     78          a2.publication_set.clear()
     79          a2.publication_set.add(p1)
     80          a2.publication_set.clear()
     81          a2.publication_set.update([p1,p2])
     82   }}}
     83   or idiomatically
     84   {{{
     85         a2.publication_set.clear()
     86         a2.publication_set.add(p1)
     87         a2.publication_set.add(p2)
     88   }}}
     89
     90   -----
     91   {{{
     92     p1.get_article_list(order_by=['headline'])
     93   }}}
     94   goes to
     95   {{{
     96     p1.article_set.order_by('headline')
     97   }}}
     98
     99}}}
     100==
     101
     102
Back to Top