add on_delete to all foreignkeys

This commit is contained in:
Stephan Telling 2018-03-04 16:26:35 +01:00
parent 663099a603
commit df5e167376
No known key found for this signature in database
GPG key ID: E2A0AE38ABC88337
7 changed files with 35 additions and 17 deletions

View file

@ -4,7 +4,7 @@ from utils.models import CampRelatedModel
class ProductCategory(CampRelatedModel): class ProductCategory(CampRelatedModel):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
camp = models.ForeignKey('camps.Camp') camp = models.ForeignKey('camps.Camp', on_delete=models.PROTECT)
def __str__(self): def __str__(self):
return self.name return self.name
@ -16,7 +16,11 @@ class ProductCategory(CampRelatedModel):
class Product(models.Model): class Product(models.Model):
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
price = models.IntegerField() price = models.IntegerField()
category = models.ForeignKey(ProductCategory, related_name="products") category = models.ForeignKey(
ProductCategory,
related_name="products",
on_delete=models.PROTECT
)
in_stock = models.BooleanField(default=True) in_stock = models.BooleanField(default=True)
class Meta: class Meta:

View file

@ -655,7 +655,11 @@ class Speaker(CampRelatedModel):
class Favorite(models.Model): class Favorite(models.Model):
user = models.ForeignKey('auth.User', related_name='favorites') user = models.ForeignKey(
'auth.User',
related_name='favorites',
on_delete=models.PROTECT
)
event_instance = models.ForeignKey('program.EventInstance') event_instance = models.ForeignKey('program.EventInstance')
class Meta: class Meta:

View file

@ -72,6 +72,7 @@ class Order(CreatedUpdatedModel):
verbose_name=_('User'), verbose_name=_('User'),
help_text=_('The user this shop order belongs to.'), help_text=_('The user this shop order belongs to.'),
related_name='orders', related_name='orders',
on_delete=models.PROTECT,
) )
paid = models.BooleanField( paid = models.BooleanField(
@ -290,7 +291,8 @@ class Product(CreatedUpdatedModel, UUIDModel):
category = models.ForeignKey( category = models.ForeignKey(
'shop.ProductCategory', 'shop.ProductCategory',
related_name='products' related_name='products',
on_delete=models.PROTECT,
) )
name = models.CharField(max_length=150) name = models.CharField(max_length=150)
@ -311,6 +313,7 @@ class Product(CreatedUpdatedModel, UUIDModel):
ticket_type = models.ForeignKey( ticket_type = models.ForeignKey(
'tickets.TicketType', 'tickets.TicketType',
on_delete=models.PROTECT,
null=True, null=True,
blank=True blank=True
) )
@ -345,8 +348,8 @@ class Product(CreatedUpdatedModel, UUIDModel):
class OrderProductRelation(CreatedUpdatedModel): class OrderProductRelation(CreatedUpdatedModel):
order = models.ForeignKey('shop.Order') order = models.ForeignKey('shop.Order', on_delete=models.PROTECT)
product = models.ForeignKey('shop.Product') product = models.ForeignKey('shop.Product', on_delete=models.PROTECT)
quantity = models.PositiveIntegerField() quantity = models.PositiveIntegerField()
handed_out = models.BooleanField(default=False) handed_out = models.BooleanField(default=False)
@ -374,7 +377,7 @@ class EpayPayment(CreatedUpdatedModel, UUIDModel):
verbose_name_plural = 'Epay Payments' verbose_name_plural = 'Epay Payments'
order = models.OneToOneField('shop.Order') order = models.OneToOneField('shop.Order')
callback = models.ForeignKey('shop.EpayCallback') callback = models.ForeignKey('shop.EpayCallback', on_delete=models.PROTECT)
txnid = models.IntegerField() txnid = models.IntegerField()
@ -402,6 +405,7 @@ class CreditNote(CreatedUpdatedModel):
verbose_name=_('User'), verbose_name=_('User'),
help_text=_('The user this credit note belongs to, if any.'), help_text=_('The user this credit note belongs to, if any.'),
related_name='creditnotes', related_name='creditnotes',
on_delete=models.PROTECT,
null=True, null=True,
blank=True blank=True
) )

View file

@ -19,7 +19,7 @@ class Sponsor(CampRelatedModel):
help_text='Name of the sponsor' help_text='Name of the sponsor'
) )
tier = models.ForeignKey('sponsors.SponsorTier') tier = models.ForeignKey('sponsors.SponsorTier', on_delete=models.PROTECT)
description = models.TextField( description = models.TextField(
help_text='A short description of the sponsorship' help_text='A short description of the sponsorship'
@ -57,6 +57,7 @@ class SponsorTier(CampRelatedModel):
camp = models.ForeignKey( camp = models.ForeignKey(
'camps.Camp', 'camps.Camp',
null=True, null=True,
on_delete=models.PROTECT,
related_name='sponsor_tiers', related_name='sponsor_tiers',
help_text='The camp this sponsor tier belongs to', help_text='The camp this sponsor tier belongs to',
) )

View file

@ -106,8 +106,8 @@ class Team(CampRelatedModel):
class TeamMember(CampRelatedModel): class TeamMember(CampRelatedModel):
user = models.ForeignKey('auth.User') user = models.ForeignKey('auth.User', on_delete=models.PROTECT)
team = models.ForeignKey('teams.Team') team = models.ForeignKey('teams.Team', on_delete=models.PROTECT)
approved = models.BooleanField(default=False) approved = models.BooleanField(default=False)
responsible = models.BooleanField(default=False) responsible = models.BooleanField(default=False)
@ -132,6 +132,7 @@ class TeamTask(CampRelatedModel):
team = models.ForeignKey( team = models.ForeignKey(
'teams.Team', 'teams.Team',
related_name='tasks', related_name='tasks',
on_delete=models.PROTECT,
help_text='The team this task belongs to', help_text='The team this task belongs to',
) )
name = models.CharField( name = models.CharField(

View file

@ -18,14 +18,14 @@ logger = logging.getLogger("bornhack.%s" % __name__)
# TicketType can be full week, one day. etc. # TicketType can be full week, one day. etc.
class TicketType(CampRelatedModel, UUIDModel): class TicketType(CampRelatedModel, UUIDModel):
name = models.TextField() name = models.TextField()
camp = models.ForeignKey('camps.Camp') camp = models.ForeignKey('camps.Camp', on_delete=models.PROTECT)
def __str__(self): def __str__(self):
return '{} ({})'.format(self.name, self.camp.title) return '{} ({})'.format(self.name, self.camp.title)
class BaseTicket(CampRelatedModel, UUIDModel): class BaseTicket(CampRelatedModel, UUIDModel):
ticket_type = models.ForeignKey('TicketType') ticket_type = models.ForeignKey('TicketType', on_delete=models.PROTECT)
checked_in = models.BooleanField(default=False) checked_in = models.BooleanField(default=False)
badge_handed_out = models.BooleanField(default=False) badge_handed_out = models.BooleanField(default=False)
@ -69,7 +69,7 @@ class BaseTicket(CampRelatedModel, UUIDModel):
class SponsorTicket(BaseTicket): class SponsorTicket(BaseTicket):
sponsor = models.ForeignKey('sponsors.Sponsor') sponsor = models.ForeignKey('sponsors.Sponsor', on_delete=models.PROTECT)
def __str__(self): def __str__(self):
return 'SponsorTicket: {}'.format(self.pk) return 'SponsorTicket: {}'.format(self.pk)
@ -93,8 +93,12 @@ class DiscountTicket(BaseTicket):
class ShopTicket(BaseTicket): class ShopTicket(BaseTicket):
order = models.ForeignKey('shop.Order', related_name='shoptickets') order = models.ForeignKey(
product = models.ForeignKey('shop.Product') 'shop.Order',
related_name='shoptickets',
on_delete=models.PROTECT
)
product = models.ForeignKey('shop.Product', on_delete=models.PROTECT)
name = models.CharField( name = models.CharField(
max_length=100, max_length=100,

View file

@ -11,8 +11,8 @@ class Village(UUIDModel, CampRelatedModel):
ordering = ['name'] ordering = ['name']
unique_together = ('slug', 'camp') unique_together = ('slug', 'camp')
contact = models.ForeignKey('auth.User') contact = models.ForeignKey('auth.User', on_delete=models.PROTECT)
camp = models.ForeignKey('camps.Camp') camp = models.ForeignKey('camps.Camp', on_delete=models.PROTECT)
name = models.CharField(max_length=255) name = models.CharField(max_length=255)
slug = models.SlugField(max_length=255, blank=True) slug = models.SlugField(max_length=255, blank=True)
description = models.TextField( description = models.TextField(