Skip to content

Commit

Permalink
Merge pull request #372 from CTPUG/feature/fix-on-delete-for-django-m…
Browse files Browse the repository at this point in the history
…aster

Explicitly set on_delete to models.CASCADE for ForeignKeys.
  • Loading branch information
hodgestar committed Sep 18, 2017
2 parents e56c729 + ef4f501 commit ee3076b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion wafer/kv/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


class KeyValue(models.Model):
group = models.ForeignKey(Group)
group = models.ForeignKey(Group, on_delete=models.CASCADE)
key = models.CharField(max_length=64, db_index=True)
value = JSONField()

Expand Down
3 changes: 2 additions & 1 deletion wafer/pages/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class Page(models.Model):
"""An extra page for the site."""
name = models.CharField(max_length=255)
slug = models.SlugField(help_text=_("Last component of the page URL"))
parent = models.ForeignKey('self', null=True, blank=True)
parent = models.ForeignKey(
'self', null=True, blank=True, on_delete=models.CASCADE)
content = MarkupField(
help_text=_("Markdown contents for the page."))
include_in_menu = models.BooleanField(
Expand Down
7 changes: 5 additions & 2 deletions wafer/schedule/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Slot(models.Model):
# requirements.

previous_slot = models.ForeignKey('self', null=True, blank=True,
on_delete=models.CASCADE,
help_text=_("Previous slot if "
"applicable (slots should "
"have either a previous "
Expand Down Expand Up @@ -144,8 +145,10 @@ class ScheduleItem(models.Model):
# Items can span multiple slots (tutorials, etc).
slots = models.ManyToManyField(Slot)

talk = models.ForeignKey(Talk, null=True, blank=True)
page = models.ForeignKey(Page, null=True, blank=True)
talk = models.ForeignKey(
Talk, null=True, blank=True, on_delete=models.CASCADE)
page = models.ForeignKey(
Page, null=True, blank=True, on_delete=models.CASCADE)
details = MarkdownTextField(
null=False, blank=True,
help_text=_("Additional details (if required)"))
Expand Down
9 changes: 6 additions & 3 deletions wafer/talks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,10 @@ class Meta:
)

talk_id = models.AutoField(primary_key=True)
talk_type = models.ForeignKey(TalkType, null=True, blank=True)
track = models.ForeignKey(Track, null=True, blank=True)
talk_type = models.ForeignKey(
TalkType, null=True, blank=True, on_delete=models.SET_NULL)
track = models.ForeignKey(
Track, null=True, blank=True, on_delete=models.SET_NULL)

title = models.CharField(max_length=1024)

Expand All @@ -137,6 +139,7 @@ class Meta:

corresponding_author = models.ForeignKey(
settings.AUTH_USER_MODEL, related_name='contact_talks',
on_delete=models.CASCADE,
help_text=_(
"The person submitting the talk (and who questions regarding the "
"talk should be addressed to)."))
Expand Down Expand Up @@ -260,4 +263,4 @@ class TalkUrl(models.Model):

description = models.CharField(max_length=256)
url = models.URLField()
talk = models.ForeignKey(Talk)
talk = models.ForeignKey(Talk, on_delete=models.CASCADE)
7 changes: 4 additions & 3 deletions wafer/tickets/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ def __str__(self):
class Ticket(models.Model):
barcode = models.IntegerField(primary_key=True)
email = models.EmailField(blank=True)
type = models.ForeignKey(TicketType)
user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name='ticket',
blank=True, null=True, on_delete=models.SET_NULL)
type = models.ForeignKey(TicketType, on_delete=models.CASCADE)
user = models.ForeignKey(
settings.AUTH_USER_MODEL, related_name='ticket',
blank=True, null=True, on_delete=models.SET_NULL)

def __str__(self):
return u'%s (%s)' % (self.barcode, self.email)

0 comments on commit ee3076b

Please sign in to comment.