Answer the question
In order to leave comments, you need to log in
Why does an argument error appear in a class?
When running the code:
class MenuItem(models.Model):
menu = models.ForeignKey(
Menu,
verbose_name = _('menu'),
)
parent = models.ForeignKey(
'self',
verbose_name = _('parent'),
related_name = u'child',
blank = True,
null = True,
)
name = models.CharField(
max_length = 150,
verbose_name = _('name'),
)
uri = models.SlugField(
verbose_name = _('URL'),
help_text = _('If you do not want to connect this item to your models, you can specify a URL explicitly'),
blank = True,
null = True,
)
visible = models.CharField(
max_length = 1,
verbose_name = _('visible'),
choices = CHOICES_VISIBLE,
default = CHOICES_VISIBLE[0][0],
)
css_class = models.CharField(
max_length = 50,
verbose_name = _('CSS class'),
help_text = u'',
blank = True,
null = True,
)
class Meta:
verbose_name = _('menu item')
verbose_name_plural = _('menu items')
def get_absolute_url(self):
return '/%s' % self.uri
def __unicode__(self):
return self.name
class MenuItem(models.Model):
File "/Users/v/Documents/app1/mysite/menu/models.py", line 36, in MenuItem
verbose_name = _('menu'),
TypeError: __init__() missing 1 required positional argument: 'on_delete'
Answer the question
In order to leave comments, you need to log in
Because you need to read the documentation (v2.2) or v3.0
Example:
class MenuItem(models.Model):
menu = models.ForeignKey(
Menu,
verbose_name = _('menu'),
on_delete=models.CASCADE,
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question