mirror of
https://github.com/django/django.git
synced 2025-10-23 21:59:11 +00:00
Fixed #21127 -- Started deprecation toward requiring on_delete for ForeignKey/OneToOneField
This commit is contained in:
committed by
Tim Graham
parent
87d55081ea
commit
c2e70f0265
@@ -32,7 +32,7 @@ class Band(models.Model):
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Album(models.Model):
|
||||
band = models.ForeignKey(Band)
|
||||
band = models.ForeignKey(Band, models.CASCADE)
|
||||
name = models.CharField(max_length=100)
|
||||
cover_art = models.FileField(upload_to='albums')
|
||||
backside_art = MyFileField(upload_to='albums_back', null=True)
|
||||
@@ -49,7 +49,7 @@ class HiddenInventoryManager(models.Manager):
|
||||
@python_2_unicode_compatible
|
||||
class Inventory(models.Model):
|
||||
barcode = models.PositiveIntegerField(unique=True)
|
||||
parent = models.ForeignKey('self', to_field='barcode', blank=True, null=True)
|
||||
parent = models.ForeignKey('self', models.SET_NULL, to_field='barcode', blank=True, null=True)
|
||||
name = models.CharField(blank=False, max_length=20)
|
||||
hidden = models.BooleanField(default=False)
|
||||
|
||||
@@ -62,7 +62,12 @@ class Inventory(models.Model):
|
||||
|
||||
|
||||
class Event(models.Model):
|
||||
main_band = models.ForeignKey(Band, limit_choices_to=models.Q(pk__gt=0), related_name='events_main_band_at')
|
||||
main_band = models.ForeignKey(
|
||||
Band,
|
||||
models.CASCADE,
|
||||
limit_choices_to=models.Q(pk__gt=0),
|
||||
related_name='events_main_band_at',
|
||||
)
|
||||
supporting_bands = models.ManyToManyField(Band, blank=True, related_name='events_supporting_band_at')
|
||||
start_date = models.DateField(blank=True, null=True)
|
||||
start_time = models.TimeField(blank=True, null=True)
|
||||
@@ -73,7 +78,7 @@ class Event(models.Model):
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Car(models.Model):
|
||||
owner = models.ForeignKey(User)
|
||||
owner = models.ForeignKey(User, models.CASCADE)
|
||||
make = models.CharField(max_length=30)
|
||||
model = models.CharField(max_length=30)
|
||||
|
||||
@@ -85,7 +90,7 @@ class CarTire(models.Model):
|
||||
"""
|
||||
A single car tire. This to test that a user can only select their own cars.
|
||||
"""
|
||||
car = models.ForeignKey(Car)
|
||||
car = models.ForeignKey(Car, models.CASCADE)
|
||||
|
||||
|
||||
class Honeycomb(models.Model):
|
||||
@@ -98,7 +103,7 @@ class Bee(models.Model):
|
||||
(Honeycomb) so the corresponding raw ID widget won't have a magnifying
|
||||
glass link to select related honeycomb instances.
|
||||
"""
|
||||
honeycomb = models.ForeignKey(Honeycomb)
|
||||
honeycomb = models.ForeignKey(Honeycomb, models.CASCADE)
|
||||
|
||||
|
||||
class Individual(models.Model):
|
||||
@@ -108,8 +113,8 @@ class Individual(models.Model):
|
||||
related instances (rendering will be called programmatically in this case).
|
||||
"""
|
||||
name = models.CharField(max_length=20)
|
||||
parent = models.ForeignKey('self', null=True, on_delete=models.SET_NULL)
|
||||
soulmate = models.ForeignKey('self', null=True, on_delete=models.CASCADE, related_name='soulmates')
|
||||
parent = models.ForeignKey('self', models.SET_NULL, null=True)
|
||||
soulmate = models.ForeignKey('self', models.CASCADE, null=True, related_name='soulmates')
|
||||
|
||||
|
||||
class Company(models.Model):
|
||||
@@ -149,7 +154,7 @@ class School(models.Model):
|
||||
|
||||
@python_2_unicode_compatible
|
||||
class Profile(models.Model):
|
||||
user = models.ForeignKey('auth.User', 'username')
|
||||
user = models.ForeignKey('auth.User', models.CASCADE, to_field='username')
|
||||
|
||||
def __str__(self):
|
||||
return self.user.username
|
||||
|
||||
Reference in New Issue
Block a user