Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to write this class for Django's data model (converting from Propel's YML format)
    primarykey
    data
    text
    <p>I am converting a web project that currently uses the <a href="http://www.propelorm.org/" rel="nofollow">Propel ORM</a>, to a django project.</p> <p>My first task is to 'port' the model schema to django's.</p> <p>I have read the django docs, but they do not appear to be in enough detail. Case in point, how may I 'port' a (contrived) table defined in the Propel YML schema as follows:</p> <pre><code> demo_ref_country: code: { type: varchar(4), required: true, index: unique } name: { type: varchar(64), required: true, index: unique } geog_region_id: { type: integer, foreignTable: demo_ref_geographic_region, foreignReference: id, required: true, onUpdate: cascade, onDelete: restrict } ccy_id: { type: integer, foreignTable: demo_ref_currency_def, foreignReference: id, required: true, onUpdate: cascade, onDelete: restrict } flag_image_path: { type: varchar(64), required: true, default: ''} created_at: ~ _indexes: idx_f1: [geog_region_id, ccy_id, created_at] _uniques: idxu_f1_key: [code, geog_region_id, ccy_id] </code></pre> <p>Here is my (feeble) attempt so far:</p> <pre><code>class Country(models.Model): code = models.CharField(max_length=4) # Erm, no index on this column ..... name = models.CharField(max_length=64) # Erm, no index on this column ..... geog_region_id = models.ForeignKey(GeogRegion) # Is this correct ? (how about ref integrity constraints ? ccy_id = models.ForeignKey(Currency) # Is this correct? flag_image_path = models.CharField(max_length=64) # How to set default on this col? created_at = models.DateTimeField() # Will this default to now() ? # Don't know how to specify indexes and unique indexes .... </code></pre> <p><strong>[Edit]</strong></p> <p>To all those suggesting that I RTFM, I understand your frustration. Its just that the documentation is not very clear to me. It is probably a Pythonic way of documentation - but coming from a C++ background, I feel the documentation could be improved to make it more accesible for people coming from different languages.</p> <p>Case in point: the documentation merely states the class name and an **options parameter in the ctor, but doesn't tell you what the possible options are. </p> <p>For example class CharField(max_length=None,[**options])</p> <p>There is a line further up in the documentation that gives a list of permissible options, which are applicable to all field types.</p> <p>However, the options are provided in the form:</p> <p>Field.optionname</p> <p>The (apparently implicit) link between a class property and a constructor argument was not clear to me. It appears that if a class has a property foo, then it means that you can pass an argument named foo to its constructor. Does that observation hold true for all Python classes?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload