On Aug 11, 2005, at 9:37 AM, ludo wrote:
Is there a standard way to have multiple files (eg one per class)
inside an app's model/ folder?

Yes -- just put multiple files in the folder :)

I seem to end up with a different app prefix for each file no matter
what I try, eg mysite/apps/myapp/boxes.py looks for a boxes_boxes table
instead of myapp_boxes.

That's by design (but you can change it if you like). If you've got "mysite.apps.myapp" in INSTALLED_APPS, and the files "boxes.py" with a Box model, you'll indeed get a model called "boxes.boxes" The first "boxes" -- which we call the "app label" -- comes from the name of the model file ("boxes.py"), and the second part -- which we call the "module name" -- comes from the module_name attribute of the class, which defaults to the pluralized name.

Similarly, the database table used matches the model name (with the dot replaced with an underscore). If all you want to do is change what the database table is, just use the "db_table" option to your model::

    class Box(meta.Model):
        db_table = "myapp_boxes"
        ...

If you'd like to actually change the model label, you can just rename "boxes.py" to "myapp.py" and you'd be good to go.

Hope that helps,

Jacob

Reply via email to