I am looking at this example django-multiple-users
When I go to sqlite shell
sqlite> .tables
auth_group classroom_subject
auth_group_permissions classroom_takenquiz
auth_permission classroom_user
classroom_answer classroom_user_groups
classroom_question classroom_user_user_permissions
classroom_quiz django_content_type
classroom_student django_migrations
classroom_student_interests django_session
classroom_studentanswer
There are 8 classess in models.py
class User(AbstractUser):
is_student = models.BooleanField(default=False)
is_teacher = models.BooleanField(default=False)
class Subject(models.Model):
class Quiz(models.Model):
class Question(models.Model):
class Answer(models.Model):
class Student(models.Model):
class TakenQuiz(models.Model):
class StudentAnswer(models.Model):
Forms.py(shown in github link above) has couple of forms.
Do forms also create tables? Where do classroom_user_user_permissions come from?
Do forms also create tables?
No, forms are used to ask input from a user. They can be "embedded" in a template, and can easily be used to for example decode the response into objects. Some of the forms directly indeed store the (updated) values in a model instance.
But a form can work for no model at all, one model, or multiple models at once. Furthermore once the form is gone, the data it carried is gone too (unless it is of course stored in a model, or in a file, or another persistent sturcture).
Where do classroom_user_user_permissions come from?
This is because you probably defined a ManyToManyField
between a User
and Userpermission
s. So not all tables directly map on models. Some relations require extra tables, since these can not directly be stored in one of the two tables.