Discussion:
How to fix TypeError: __init__() missing 1 required positional
Abba Haruna
2018-11-22 18:52:02 UTC
Permalink
from django.db import models

class Food(models.Model):
name = models.CharField(max_length=30)
picture = models.ImageField(upload_to='images/', null=True)
def __unicode__(self):
return self.name
class Town(models.Model):
name = models.CharField(max_length=30)

def __unicode__(self):
return self.name
class Restaurant(models.Model):
name = models.CharField(max_length=100)
desc = models.CharField(max_length=100)
menu = models.CharField(max_length=100)
web = models.CharField(max_length=100)
phone = models.CharField(max_length=40)
address = models.CharField(max_length=100)
post_code = models.CharField(max_length=20)
picture = models.ImageField(upload_to='images/', null=True)
map = models.ImageField(upload_to='images/', null=True)
gmap_url = models.CharField(max_length=200, null=True)
food = models.ForeignKey(Food)
town = models.ForeignKey(Town)
STARS = ((1,'one'),
(2,'two'),
(3,'three'),
(4,'four'),)
votes = models.IntegerField(choices=STARS, default=4)
def __unicode__(self):
return self.name
def __str__(self):
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/de6ad3df-e330-43e1-875a-58895e245851%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
vineeth sagar
2018-11-22 20:06:37 UTC
Permalink
For a foreign keys you have to specify an on_delete attribute,

food=models.ForiegnKey(Food,on_delete=models.CASCADE)

If a row in the parent table(food for example) is deleted this will cause
the row/s that refers to that particular food item in your Restraunt model
be deleted.

on_delete can be given other options as SET_NULL,DO_NOTHING. Refer the docs
they are extensive on this topic.
Post by Abba Haruna
from django.db import models
name = models.CharField(max_length=30)
picture = models.ImageField(upload_to='images/', null=True)
return self.name
name = models.CharField(max_length=30)
return self.name
name = models.CharField(max_length=100)
desc = models.CharField(max_length=100)
menu = models.CharField(max_length=100)
web = models.CharField(max_length=100)
phone = models.CharField(max_length=40)
address = models.CharField(max_length=100)
post_code = models.CharField(max_length=20)
picture = models.ImageField(upload_to='images/', null=True)
map = models.ImageField(upload_to='images/', null=True)
gmap_url = models.CharField(max_length=200, null=True)
food = models.ForeignKey(Food)
town = models.ForeignKey(Town)
STARS = ((1,'one'),
(2,'two'),
(3,'three'),
(4,'four'),)
votes = models.IntegerField(choices=STARS, default=4)
return self.name
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/
msgid/django-users/de6ad3df-e330-43e1-875a-58895e245851%40googlegroups.com
<https://groups.google.com/d/msgid/django-users/de6ad3df-e330-43e1-875a-58895e245851%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAMMZq8OuObyCbPXrwb47uSozX3sk7RXPiHaJnZxV%3Dk6SPjYpuA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Jason
2018-11-23 03:39:01 UTC
Permalink
on_delete is a required parameter now in django 2.0

https://docs.djangoproject.com/en/2.0/releases/2.0/#features-removed-in-2-0


- The on_delete argument for ForeignKey and OneToOneField is now
required in models and migrations. Consider squashing migrations so that
you have fewer of them to update.
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/c3ea951d-4426-4973-b1bf-1d645402d1bd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Abba Haruna
2018-11-26 13:30:15 UTC
Permalink
thank you
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+***@googlegroups.com.
To post to this group, send email to django-***@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/23a22766-8296-416c-8734-a3771eb6beb0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...