Models

class cards.models.Cards(*args, **kwargs)[source]

Bases: Model

The Cards class is a model class that represents a card in the database.

The class has the following attributes:

  • english_word: a CharField that stores the English word on the card

  • russian_word: a CharField that stores the Russian translation of the word

  • word_usage: a TextField that stores the usage of the word in a sentence

  • img: an ImageField that stores the image of the card

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

collections_set

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.

english_word

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

img

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

objects = <django.db.models.manager.Manager object>
russian_word

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

save(*args, **kwargs)[source]

The save function is a built-in function that saves the image to the database. The img variable opens up our image file and stores it as an Image object. We then check if either height or width of our image is greater than 50 pixels (our desired size). If so, we create a new_img tuple with 50 as both values and use it to resize our original img object using thumbnail(). Finally, we save this resized version back into its original path.

Parameters:
  • args – Send a non-keyworded variable length argument list to the function

  • kwargs – Pass keyworded, variable-length argument list to a function

Returns:

None

word_usage

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

class cards.models.Collections(*args, **kwargs)[source]

Bases: Model

The Collections class is a model class that represents a collection.

The class has the following attributes:

  • name: a CharField that stores the name of the collection.

  • owner: a ForeignKey that stores the owner of the collection.

  • cards: a ManyToManyField that stores the cards in the collection.

  • order_list: an ArrayField that stores the order of the cards in the collection.

  • img: an ImageField that stores the image of the collection.

exception DoesNotExist

Bases: ObjectDoesNotExist

exception MultipleObjectsReturned

Bases: MultipleObjectsReturned

cards

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.

id

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

img

Just like the FileDescriptor, but for ImageFields. The only difference is assigning the width/height to the width_field/height_field, if appropriate.

name

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>
order_list

A wrapper for a deferred-loading field. When the value is read from this object the first time, the query is executed.

owner

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.

owner_id
save(*args, **kwargs)[source]

The save function is a built-in function that saves the image to the database. The img variable opens up our image file and stores it as an Image object. We then check if either height or width of our image is greater than 50 pixels (our desired size). If so, we create a new_img tuple with 50 as both values and use it to resize our original img object using thumbnail(). Finally, we save this resized version back into its original path.

Parameters:
  • args – Send a non-keyworded variable length argument list to the function

  • kwargs – Pass keyworded, variable-length argument list to a function

Returns:

None