Модели (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.place is a ForwardOneToOneDescriptor instance.

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.toppings and Topping.pizzas are ManyToManyDescriptor instances.

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.toppings and Topping.pizzas are ManyToManyDescriptor instances.

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.children is a ReverseManyToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.place is a ForwardOneToOneDescriptor instance.

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.toppings and Topping.pizzas are ManyToManyDescriptor instances.

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.toppings and Topping.pizzas are ManyToManyDescriptor instances.

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.children is a ReverseManyToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.children is a ReverseManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.parent is a ForwardManyToOneDescriptor instance.

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.