[2.2.x] Changed tuple Mate.unique_together/permissions to lists in docs.
Backport of 0c916255eb
from master
This commit is contained in:
parent
88bf635c35
commit
46416554f3
|
@ -309,7 +309,7 @@ Django quotes column and table names behind the scenes.
|
||||||
Add, change, delete, and view permissions are automatically created for each
|
Add, change, delete, and view permissions are automatically created for each
|
||||||
model. This example specifies an extra permission, ``can_deliver_pizzas``::
|
model. This example specifies an extra permission, ``can_deliver_pizzas``::
|
||||||
|
|
||||||
permissions = (("can_deliver_pizzas", "Can deliver pizzas"),)
|
permissions = [('can_deliver_pizzas', 'Can deliver pizzas')]
|
||||||
|
|
||||||
This is a list or tuple of 2-tuples in the format ``(permission_code,
|
This is a list or tuple of 2-tuples in the format ``(permission_code,
|
||||||
human_readable_permission_name)``.
|
human_readable_permission_name)``.
|
||||||
|
@ -412,17 +412,17 @@ Django quotes column and table names behind the scenes.
|
||||||
|
|
||||||
Sets of field names that, taken together, must be unique::
|
Sets of field names that, taken together, must be unique::
|
||||||
|
|
||||||
unique_together = (("driver", "restaurant"),)
|
unique_together = [['driver', 'restaurant']]
|
||||||
|
|
||||||
This is a tuple of tuples that must be unique when considered together.
|
This is a list of lists that must be unique when considered together.
|
||||||
It's used in the Django admin and is enforced at the database level (i.e., the
|
It's used in the Django admin and is enforced at the database level (i.e., the
|
||||||
appropriate ``UNIQUE`` statements are included in the ``CREATE TABLE``
|
appropriate ``UNIQUE`` statements are included in the ``CREATE TABLE``
|
||||||
statement).
|
statement).
|
||||||
|
|
||||||
For convenience, unique_together can be a single tuple when dealing with a single
|
For convenience, ``unique_together`` can be a single list when dealing with
|
||||||
set of fields::
|
a single set of fields::
|
||||||
|
|
||||||
unique_together = ("driver", "restaurant")
|
unique_together = ['driver', 'restaurant']
|
||||||
|
|
||||||
A :class:`~django.db.models.ManyToManyField` cannot be included in
|
A :class:`~django.db.models.ManyToManyField` cannot be included in
|
||||||
unique_together. (It's not clear what that would even mean!) If you
|
unique_together. (It's not clear what that would even mean!) If you
|
||||||
|
|
|
@ -277,10 +277,10 @@ can or cannot do with ``Task`` instances, specific to your application::
|
||||||
class Task(models.Model):
|
class Task(models.Model):
|
||||||
...
|
...
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (
|
permissions = [
|
||||||
("change_task_status", "Can change the status of tasks"),
|
("change_task_status", "Can change the status of tasks"),
|
||||||
("close_task", "Can remove a task by setting its status as closed"),
|
("close_task", "Can remove a task by setting its status as closed"),
|
||||||
)
|
]
|
||||||
|
|
||||||
The only thing this does is create those extra permissions when you run
|
The only thing this does is create those extra permissions when you run
|
||||||
:djadmin:`manage.py migrate <migrate>` (the function that creates permissions
|
:djadmin:`manage.py migrate <migrate>` (the function that creates permissions
|
||||||
|
|
|
@ -328,12 +328,12 @@ inherit the permissions of the concrete model they subclass::
|
||||||
|
|
||||||
class Person(models.Model):
|
class Person(models.Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
permissions = (('can_eat_pizzas', 'Can eat pizzas'),)
|
permissions = [('can_eat_pizzas', 'Can eat pizzas')]
|
||||||
|
|
||||||
class Student(Person):
|
class Student(Person):
|
||||||
class Meta:
|
class Meta:
|
||||||
proxy = True
|
proxy = True
|
||||||
permissions = (('can_deliver_pizzas', 'Can deliver pizzas'),)
|
permissions = [('can_deliver_pizzas', 'Can deliver pizzas')]
|
||||||
|
|
||||||
>>> # Fetch the content type for the proxy model.
|
>>> # Fetch the content type for the proxy model.
|
||||||
>>> content_type = ContentType.objects.get_for_model(Student, for_concrete_model=False)
|
>>> content_type = ContentType.objects.get_for_model(Student, for_concrete_model=False)
|
||||||
|
|
|
@ -367,7 +367,7 @@ Consider the following two models::
|
||||||
birthdate = models.DateField()
|
birthdate = models.DateField()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (('first_name', 'last_name'),)
|
unique_together = [['first_name', 'last_name']]
|
||||||
|
|
||||||
class Book(models.Model):
|
class Book(models.Model):
|
||||||
name = models.CharField(max_length=100)
|
name = models.CharField(max_length=100)
|
||||||
|
@ -411,7 +411,7 @@ name::
|
||||||
objects = PersonManager()
|
objects = PersonManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (('first_name', 'last_name'),)
|
unique_together = [['first_name', 'last_name']]
|
||||||
|
|
||||||
Now books can use that natural key to refer to ``Person`` objects::
|
Now books can use that natural key to refer to ``Person`` objects::
|
||||||
|
|
||||||
|
@ -459,7 +459,7 @@ Firstly, you need to add another method -- this time to the model itself::
|
||||||
objects = PersonManager()
|
objects = PersonManager()
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
unique_together = (('first_name', 'last_name'),)
|
unique_together = [['first_name', 'last_name']]
|
||||||
|
|
||||||
def natural_key(self):
|
def natural_key(self):
|
||||||
return (self.first_name, self.last_name)
|
return (self.first_name, self.last_name)
|
||||||
|
|
Loading…
Reference in New Issue