kopia lustrzana https://github.com/wagtail/wagtail
add on_delete argument to ParentalKey & ForeignKey
rodzic
26d9fb42a3
commit
70eb2b6ae3
|
@ -114,7 +114,7 @@ For example:
|
|||
from wagtail.api import APIField
|
||||
|
||||
class BlogPageAuthor(Orderable):
|
||||
page = models.ForeignKey('blog.BlogPage', related_name='authors')
|
||||
page = models.ForeignKey('blog.BlogPage', on_delete=models.CASCADE, related_name='authors')
|
||||
name = models.CharField(max_length=255)
|
||||
|
||||
api_fields = [
|
||||
|
@ -125,7 +125,7 @@ For example:
|
|||
class BlogPage(Page):
|
||||
published_date = models.DateTimeField()
|
||||
body = RichTextField()
|
||||
feed_image = models.ForeignKey('wagtailimages.Image', ...)
|
||||
feed_image = models.ForeignKey('wagtailimages.Image', on_delete=models.CASCADE, ...)
|
||||
private_field = models.CharField(max_length=255)
|
||||
|
||||
# Export fields over the API
|
||||
|
|
|
@ -143,7 +143,7 @@ For each field you would like to be translatable, duplicate it for every languag
|
|||
body_fr = StreamField(...)
|
||||
|
||||
# Language-independent fields don't need to be duplicated
|
||||
thumbnail_image = models.ForeignKey('wagtailimages.image', ...)
|
||||
thumbnail_image = models.ForeignKey('wagtailimages.image', on_delete=models.CASCADE, ...)
|
||||
|
||||
.. note::
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ Here's an example:
|
|||
|
||||
|
||||
class CustomRendition(AbstractRendition):
|
||||
image = models.ForeignKey(CustomImage, related_name='renditions')
|
||||
image = models.ForeignKey(CustomImage, on_delete=models.CASCADE, related_name='renditions')
|
||||
|
||||
class Meta:
|
||||
unique_together = (
|
||||
|
|
|
@ -436,7 +436,7 @@ Add a new ``BlogPageGalleryImage`` model to ``models.py``:
|
|||
|
||||
|
||||
class BlogPageGalleryImage(Orderable):
|
||||
page = ParentalKey(BlogPage, related_name='gallery_images')
|
||||
page = ParentalKey(BlogPage, on_delete=models.CASCADE, related_name='gallery_images')
|
||||
image = models.ForeignKey(
|
||||
'wagtailimages.Image', on_delete=models.CASCADE, related_name='+'
|
||||
)
|
||||
|
|
|
@ -23,7 +23,7 @@ You can do this as shown below.
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='custom_form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='custom_form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
@ -74,7 +74,7 @@ Example:
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
@ -135,7 +135,7 @@ The following example shows how to add a username to the CSV export:
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
@ -213,7 +213,7 @@ Example:
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
@ -309,7 +309,7 @@ The following example shows how to create a multi-step form.
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
@ -455,7 +455,7 @@ First, you need to collect results as shown below:
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
|
|
@ -38,7 +38,7 @@ Within the ``models.py`` of one of your apps, create a model that extends ``wagt
|
|||
|
||||
|
||||
class FormField(AbstractFormField):
|
||||
page = ParentalKey('FormPage', related_name='form_fields')
|
||||
page = ParentalKey('FormPage', on_delete=models.CASCADE, related_name='form_fields')
|
||||
|
||||
|
||||
class FormPage(AbstractEmailForm):
|
||||
|
|
|
@ -150,7 +150,7 @@ Using an example from the Wagtail demo site, here's what the tag model and the r
|
|||
from taggit.models import TaggedItemBase
|
||||
|
||||
class BlogPageTag(TaggedItemBase):
|
||||
content_object = ParentalKey('demo.BlogPage', related_name='tagged_items')
|
||||
content_object = ParentalKey('demo.BlogPage', on_delete=models.CASCADE, related_name='tagged_items')
|
||||
|
||||
class BlogPage(Page):
|
||||
...
|
||||
|
|
|
@ -318,7 +318,7 @@ Let's look at the example of adding related links to a :class:`~wagtail.core.mod
|
|||
# Orderable helper class, and what amounts to a ForeignKey link
|
||||
# to the model we want to add related links to (BookPage)
|
||||
class BookPageRelatedLinks(Orderable, RelatedLink):
|
||||
page = ParentalKey('demo.BookPage', related_name='related_links')
|
||||
page = ParentalKey('demo.BookPage', on_delete=models.CASCADE, related_name='related_links')
|
||||
|
||||
class BookPage(Page):
|
||||
# ...
|
||||
|
|
|
@ -77,7 +77,7 @@ This example represents a typical blog post:
|
|||
|
||||
|
||||
class BlogPageRelatedLink(Orderable):
|
||||
page = ParentalKey(BlogPage, related_name='related_links')
|
||||
page = ParentalKey(BlogPage, on_delete=models.CASCADE, related_name='related_links')
|
||||
name = models.CharField(max_length=255)
|
||||
url = models.URLField()
|
||||
|
||||
|
@ -384,7 +384,7 @@ For example, the following inline model can be used to add related links (a list
|
|||
|
||||
|
||||
class BlogPageRelatedLink(Orderable):
|
||||
page = ParentalKey(BlogPage, related_name='related_links')
|
||||
page = ParentalKey(BlogPage, on_delete=models.CASCADE, related_name='related_links')
|
||||
name = models.CharField(max_length=255)
|
||||
url = models.URLField()
|
||||
|
||||
|
|
|
@ -219,7 +219,7 @@ To do this, inherit from ``index.Indexed`` and add some ``search_fields`` to the
|
|||
class Book(index.Indexed, models.Model):
|
||||
title = models.CharField(max_length=255)
|
||||
genre = models.CharField(max_length=255, choices=GENRE_CHOICES)
|
||||
author = models.ForeignKey(Author)
|
||||
author = models.ForeignKey(Author, on_delete=models.CASCADE)
|
||||
published_date = models.DateTimeField()
|
||||
|
||||
search_fields = [
|
||||
|
|
|
@ -137,8 +137,8 @@ To attach multiple adverts to a page, the ``SnippetChooserPanel`` can be placed
|
|||
...
|
||||
|
||||
class BookPageAdvertPlacement(Orderable, models.Model):
|
||||
page = ParentalKey('demo.BookPage', related_name='advert_placements')
|
||||
advert = models.ForeignKey('demo.Advert', related_name='+')
|
||||
page = ParentalKey('demo.BookPage', on_delete=models.CASCADE, related_name='advert_placements')
|
||||
advert = models.ForeignKey('demo.Advert', on_delete=models.CASCADE, related_name='+')
|
||||
|
||||
class Meta:
|
||||
verbose_name = "advert placement"
|
||||
|
@ -218,7 +218,7 @@ Adding tags to snippets is very similar to adding tags to pages. The only differ
|
|||
from taggit.managers import TaggableManager
|
||||
|
||||
class AdvertTag(TaggedItemBase):
|
||||
content_object = ParentalKey('demo.Advert', related_name='tagged_items')
|
||||
content_object = ParentalKey('demo.Advert', on_delete=models.CASCADE, related_name='tagged_items')
|
||||
|
||||
@register_snippet
|
||||
class Advert(ClusterableModel):
|
||||
|
|
Ładowanie…
Reference in New Issue