Модели (Models)
Модуль содержит Django модели для управления пользователями, домашними заданиями и отправками работ.
Модели данных для системы проверки домашних заданий.
Содержит модели для: - Профилей пользователей (студенты и преподаватели) - Домашних заданий - Отправленных работ студентов
- assignments.models.validate_file_size(file)[исходный код]
Валидатор размера файла (максимум 10 МБ).
- Параметры:
file – Загружаемый файл
- Исключение:
ValidationError – Если размер файла превышает лимит
- assignments.models.validate_file_extension(file)[исходный код]
Валидатор расширения файла.
- Параметры:
file – Загружаемый файл
- Исключение:
ValidationError – Если расширение файла не разрешено
- class assignments.models.UserProfile(*args, **kwargs)[исходный код]
Базовые классы:
ModelПрофиль пользователя с ролью
- ROLE_CHOICES = [('student', 'Студент'), ('teacher', 'Преподаватель')]
- user
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
- role
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property is_student
- property is_teacher
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- get_role_display(*, field=<django.db.models.fields.CharField: role>)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- user_id
- assignments.models.create_user_profile(sender, instance, created, **kwargs)[исходный код]
Автоматически создаем профиль при создании пользователя
- assignments.models.save_user_profile(sender, instance, **kwargs)[исходный код]
Сохраняем профиль при сохранении пользователя
- class assignments.models.Course(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель курса
- title
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- teachers
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- students
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- enrollment_requests
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- homeworks
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- class assignments.models.Homework(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель домашнего задания
- course
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- title
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- due_date
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- course_id
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_next_by_due_date(*, field=<django.db.models.fields.DateTimeField: due_date>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- get_previous_by_due_date(*, field=<django.db.models.fields.DateTimeField: due_date>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- submissions
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- class assignments.models.Submission(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель отправки работы студентом
- homework
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- student
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- solution_file
The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:
>>> from myapp.models import MyModel >>> instance = MyModel.objects.get(pk=1) >>> instance.file.size
Assign a file object on assignment so you can do:
>>> with open('/path/to/hello.world') as f: ... instance.file = File(f)
- submitted_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- grade
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- feedback
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- get_next_by_submitted_at(*, field=<django.db.models.fields.DateTimeField: submitted_at>, is_next=True, **kwargs)
- get_previous_by_submitted_at(*, field=<django.db.models.fields.DateTimeField: submitted_at>, is_next=False, **kwargs)
- homework_id
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- student_id
- class assignments.models.CourseEnrollmentRequest(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель заявки студента на зачисление на курс
- STATUS_CHOICES = [('pending', 'На рассмотрении'), ('approved', 'Одобрена'), ('rejected', 'Отклонена')]
- course
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- student
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- status
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- message
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- processed_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- processed_by
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- course_id
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- get_status_display(*, field=<django.db.models.fields.CharField: status>)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- processed_by_id
- student_id
UserProfile
- class assignments.models.UserProfile(*args, **kwargs)[исходный код]
Базовые классы:
ModelПрофиль пользователя с ролью
Модель профиля пользователя, содержащая информацию о роли (студент или преподаватель).
Поля:
user- связь с моделью User (один к одному)role- роль пользователя („student“ или „teacher“)
Свойства:
is_student- проверка, является ли пользователь студентомis_teacher- проверка, является ли пользователь преподавателем
- ROLE_CHOICES = [('student', 'Студент'), ('teacher', 'Преподаватель')]
- user
Accessor to the related object on the forward side of a one-to-one relation.
In the example:
class Restaurant(Model): place = OneToOneField(Place, related_name='restaurant')
Restaurant.placeis aForwardOneToOneDescriptorinstance.
- role
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- property is_student
- property is_teacher
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- get_role_display(*, field=<django.db.models.fields.CharField: role>)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- user_id
Course
- class assignments.models.Course(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель курса
Модель курса. Курсы содержат домашние задания и связывают преподавателей со студентами.
Поля:
title- название курсаdescription- описание курсаteachers- преподаватели курса (ManyToMany с User)students- студенты, записанные на курс (ManyToMany с User)created_at- дата создания (автоматически)
Связи:
teaching_courses- обратная связь от User к курсам, которые он преподаетenrolled_courses- обратная связь от User к курсам, на которые он записанhomeworks- все домашние задания этого курса
- title
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- teachers
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- students
Accessor to the related objects manager on the forward and reverse sides of a many-to-many relation.
In the example:
class Pizza(Model): toppings = ManyToManyField(Topping, related_name='pizzas')
Pizza.toppingsandTopping.pizzasareManyToManyDescriptorinstances.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- enrollment_requests
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- homeworks
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
Homework
- class assignments.models.Homework(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель домашнего задания
Модель домашнего задания. Каждое задание принадлежит конкретному курсу.
Поля:
course- курс, к которому относится задание (ForeignKey)title- заголовок заданияdescription- описание заданияdue_date- срок сдачиcreated_at- дата создания (автоматически)
Связи:
submissions- все отправленные работы по этому заданию
- course
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- title
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- description
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- due_date
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- created_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- course_id
- get_next_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=True, **kwargs)
- get_next_by_due_date(*, field=<django.db.models.fields.DateTimeField: due_date>, is_next=True, **kwargs)
- get_previous_by_created_at(*, field=<django.db.models.fields.DateTimeField: created_at>, is_next=False, **kwargs)
- get_previous_by_due_date(*, field=<django.db.models.fields.DateTimeField: due_date>, is_next=False, **kwargs)
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- submissions
Accessor to the related objects manager on the reverse side of a many-to-one relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Parent.childrenis aReverseManyToOneDescriptorinstance.Most of the implementation is delegated to a dynamically defined manager class built by
create_forward_many_to_many_manager()defined below.
Submission
- class assignments.models.Submission(*args, **kwargs)[исходный код]
Базовые классы:
ModelМодель отправки работы студентом
Модель отправленной работы студента.
Поля:
homework- связь с домашним заданиемstudent- связь с пользователем (студентом)solution_file- загруженный файл с решениемsubmitted_at- дата и время отправкиgrade- оценка (опционально)feedback- отзыв преподавателя (опционально)
Ограничения:
Уникальная пара (homework, student) - студент может отправить только одну работу по каждому заданию
- homework
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- student
Accessor to the related object on the forward side of a many-to-one or one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model): parent = ForeignKey(Parent, related_name='children')
Child.parentis aForwardManyToOneDescriptorinstance.
- solution_file
The descriptor for the file attribute on the model instance. Return a FieldFile when accessed so you can write code like:
>>> from myapp.models import MyModel >>> instance = MyModel.objects.get(pk=1) >>> instance.file.size
Assign a file object on assignment so you can do:
>>> with open('/path/to/hello.world') as f: ... instance.file = File(f)
- submitted_at
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- grade
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- feedback
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- exception DoesNotExist
Базовые классы:
ObjectDoesNotExist
- exception MultipleObjectsReturned
Базовые классы:
MultipleObjectsReturned
- get_next_by_submitted_at(*, field=<django.db.models.fields.DateTimeField: submitted_at>, is_next=True, **kwargs)
- get_previous_by_submitted_at(*, field=<django.db.models.fields.DateTimeField: submitted_at>, is_next=False, **kwargs)
- homework_id
- id
A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.
- objects = <django.db.models.manager.Manager object>
- student_id
Сигналы
- assignments.models.create_user_profile(sender, instance, created, **kwargs)[исходный код]
Автоматически создаем профиль при создании пользователя
Автоматически создает профиль пользователя при создании нового User.
- assignments.models.save_user_profile(sender, instance, **kwargs)[исходный код]
Сохраняем профиль при сохранении пользователя
Автоматически сохраняет профиль пользователя при сохранении User.