summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorMatt Wiens <mwiens91@gmail.com>2018-12-27 16:34:14 -0800
committerTim Graham <timograham@gmail.com>2018-12-27 19:34:14 -0500
commite817ae74da0e515db31907ebcb2d00bcf7c3f5bc (patch)
tree95a250a4d845b9c8f4f8416fc8962cfe1937951e /docs
parentdd8ed64113947ed066b83e443053e389e8f77ebc (diff)
Followed style guide for model attribute ordering.
Diffstat (limited to 'docs')
-rw-r--r--docs/topics/db/examples/many_to_many.txt12
-rw-r--r--docs/topics/serialization.txt14
2 files changed, 12 insertions, 14 deletions
diff --git a/docs/topics/db/examples/many_to_many.txt b/docs/topics/db/examples/many_to_many.txt
index 53926d13fe..ed4a093964 100644
--- a/docs/topics/db/examples/many_to_many.txt
+++ b/docs/topics/db/examples/many_to_many.txt
@@ -17,22 +17,22 @@ objects, and a ``Publication`` has multiple ``Article`` objects:
class Publication(models.Model):
title = models.CharField(max_length=30)
- def __str__(self):
- return self.title
-
class Meta:
ordering = ('title',)
+ def __str__(self):
+ return self.title
+
class Article(models.Model):
headline = models.CharField(max_length=100)
publications = models.ManyToManyField(Publication)
- def __str__(self):
- return self.headline
-
class Meta:
ordering = ('headline',)
+ def __str__(self):
+ return self.headline
+
What follows are examples of operations that can be performed using the Python
API facilities. Note that if you are using :ref:`an intermediate model
<intermediary-manytomany>` for a many-to-many relationship, some of the related
diff --git a/docs/topics/serialization.txt b/docs/topics/serialization.txt
index fba5113e40..e4e92fca43 100644
--- a/docs/topics/serialization.txt
+++ b/docs/topics/serialization.txt
@@ -404,13 +404,12 @@ name::
return self.get(first_name=first_name, last_name=last_name)
class Person(models.Model):
- objects = PersonManager()
-
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
-
birthdate = models.DateField()
+ objects = PersonManager()
+
class Meta:
unique_together = (('first_name', 'last_name'),)
@@ -453,19 +452,18 @@ So how do you get Django to emit a natural key when serializing an object?
Firstly, you need to add another method -- this time to the model itself::
class Person(models.Model):
- objects = PersonManager()
-
first_name = models.CharField(max_length=100)
last_name = models.CharField(max_length=100)
-
birthdate = models.DateField()
- def natural_key(self):
- return (self.first_name, self.last_name)
+ objects = PersonManager()
class Meta:
unique_together = (('first_name', 'last_name'),)
+ def natural_key(self):
+ return (self.first_name, self.last_name)
+
That method should always return a natural key tuple -- in this
example, ``(first name, last name)``. Then, when you call
``serializers.serialize()``, you provide ``use_natural_foreign_keys=True``