#6344: Refactored manage.py inspectdb
------------------------------------------------------------+---------------
          Reporter:  Daniel Pope <[EMAIL PROTECTED]>  |         Owner:  nobody
            Status:  new                                    |     Milestone:    
    
         Component:  django-admin.py inspectdb              |       Version:  
SVN   
        Resolution:                                         |      Keywords:    
    
             Stage:  Accepted                               |     Has_patch:  1 
    
        Needs_docs:  0                                      |   Needs_tests:  0 
    
Needs_better_patch:  1                                      |  
------------------------------------------------------------+---------------
Comment (by maubp):

 There's a bug in Daniel's patch, inspectdb_refactor.diff (13.1 kB) dated
 01/08/08.


 {{{
         146         def __str__(self):
         147             s='class %s(models.Model):\n' % self.model_name
         148
         149             keys, rels, ids, other=self.group_fields()
         150             if not keys:
         151                 s+='    # Warning: this model needs a field
 with primary_key=True\n\n'
         152
         153             for f in keys:
         154                 s+='    %s\n'%self._field_as_str(f)
         155             if keys:
         156                 s+='\n'
         157
         158             for f in ids:
         159                 s+='    %s\n'%self._field_as_str(f)
         160             if ids:
         161                 s+='\n'
         162
         163             for r in rels:
         164                 s+='    %s\n'%self._rel_as_str(f)
         165             if rels:
         166                 s+='\n'
         167
         168             for f in other:
         169                 s+='    %s\n'%self._field_as_str(f)
         170             if other:
         171                 s+='\n'
 }}}


 Line 163, should be "for f in rels" not "for r in rels"

 On a style point, I would have written this section more like:


 {{{
 for group in [keys, ids, rels, other] :
     if group :
         s+= "\n".join(['    %s'%self._field_as_str(f) for f in ids)]) +
 "\n"
 }}}


 Similarly for the Database object's __str__ method,

 {{{

 class Database(object):
     ...
     def __str__(self):
         return "\n\n".join([str(m) for m in self.models.values()])
 }}}


 But this is subjective and I don't know which follows the Django coding
 style best.


 ----

 I've being trying the inspectdb tool on a MySQL database, and particularly
 liked three bits of this patch:
     * automatic sorting of the models/tables (a very tedious manual task)
     * db_column is always specified (I'm already familiar with our schema,
 so I want to see the original column names)
     * warning comment if no primary_key is detected (very helpful for
 diagnostics, see also ticket 373)

-- 
Ticket URL: <http://code.djangoproject.com/ticket/6344#comment:5>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to