Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <pre><code>Class demo_ref_country(models.Model) code= models.CharField(max_length=4, db_index=True, null=False) name= models.CharField(max_length=64, db_index=True, null=False) geog_region = models.ForeignKey(geographic_region, null=False) ccy = models.ForeignKey(Currency_def, null=False) flag = models.ImageField(upload_to='path to directory', null=False, default="home") created_at = models.DateTimeField(auto_now_add=True, db_index=True) class Meta: unique_together = (code, geog_region, ccy) </code></pre> <p>You can set default values,, db_index paramaeter creates indexes for related fields. You can use unique=True for seperate fields, but tahat unique together will check uniqueness in columns together.</p> <p>UPDATE: First of all, i advice you to read documentatin carefully, since django gives you a lot of opportunuties, some of them have some restrictions... Such as, unique_together option is used <strong>just for</strong> django admin. It means if you create a new record or edit it via admin interface, it will be used. If you will alsa insert data with other ways (like a DataModel.objects.create statement) its better you use uniaue=True in field definition like:</p> <pre><code>code= models.CharField(max_length=4, db_index=True, null=False, unique=True) </code></pre> <p>ForeignKey fields are unique as default, so you do not need to define uniqueness for them.</p> <p>Django supports method override, so you can override Model save and delete methods as you like. <a href="http://docs.djangoproject.com/en/dev/ref/models/instances/?from=olddocs" rel="nofollow">check it here</a>. Django also allows you to write raw sql queries <a href="http://docs.djangoproject.com/en/1.2/topics/db/sql/" rel="nofollow">you can check it here</a></p> <p>As i explained, unique together is a django admin feature. So dont forget to add unique=True to required fields. Unique together also allows you to define diffrent unique pairs, such as;</p> <pre><code>unique_together = (('id','code'),('code','ccy','geog_region')) </code></pre> <p>That means, id and code must be unique together <strong>and</strong> code, ccy and geog_region must be unique together</p> <p>UPDATE 2: Prior to your question update...</p> <p>It is better yo start from <a href="http://docs.djangoproject.com/en/1.2/intro/tutorial01/" rel="nofollow">tutorials</a>. It defines basics with good examples.</p> <p>As for doc style, let me give you an example, but if you start from tutors, it will be easier for you... There are from model structure... <a href="http://docs.djangoproject.com/en/1.2/ref/models/fields/" rel="nofollow">Doc here</a></p> <pre><code>BooleanField class BooleanField(**options) </code></pre> <p>that defines, the basic structure of a database field, () is used, and it has some parameters taken as options. that is the part:</p> <pre><code>models.BooleansField() </code></pre> <p>Since this is a field struvture, available options are defines as:</p> <pre><code>unique Field.unique </code></pre> <p>So,</p> <pre><code>models.BooleansField(unique=True) </code></pre> <p>That is the general usage. Since uniqu is a basic option available to all field types, it classified as field.unique. There are some options available to a single field type, like symmetrical which is a ManyToMany field option, is classified as ManyToMany.Symmetrical</p> <p>For the <a href="http://docs.djangoproject.com/en/1.2/ref/models/querysets/" rel="nofollow">queryset</a> </p> <pre><code>class QuerySet([model=None]) </code></pre> <p>That is used as you use a function, but you use it to filter a model, with other words, write a filter query to execute... It has some methods, like filter...</p> <pre><code>filter(**kwargs) </code></pre> <p>Since this takes some kwargs, and as i told before, this is used to filter your query results, so kwargs must be your model fields (database table fields) Like:</p> <pre><code>MyModel.objects.filter(id=15) </code></pre> <p>what object is defines in the doc, but it is a manager that helps you get related objects.</p> <p>Doc contains good examples, but you have to start from tutors, that is what i can advice you...</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.
 

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