예제 #1
0
파일: models.py 프로젝트: sycct/wikitowns
class BookRecommendation(models.Model):
    isbn = ISBNField()
    title = models.CharField(max_length=500)
    recommended_by = models.ForeignKey(User)
    category = models.ForeignKey(Category)
    subcategory = models.ForeignKey(SubCategory)
    book_author = models.CharField(max_length=128)
    book_description = models.CharField(max_length=10000)  # check length is ok
    created_date = models.DateTimeField(default=timezone.now)
    # book_url is a link to the book on amazon
    book_url = models.URLField(max_length=2000)
    book_image_url = models.URLField(max_length=500)  # check length is ok
    book_publish_date = models.DateField()
    upvote = models.ManyToManyField(User, related_name='book_upvote')
    downvote = models.ManyToManyField(User, related_name='book_downvote')
    bookmark = models.ManyToManyField(User, related_name='book_bookmark')

    @property
    def total_votes(self):
        total_upvotes = self.upvote.count()
        total_downvotes = self.downvote.count()

        return total_upvotes - total_downvotes

    class Meta:
        unique_together = (("category", "subcategory", "isbn"),)

    def __str__(self):
        return self.title
예제 #2
0
class Book(models.Model):
    """
        Book Model
    """
    title = models.CharField(max_length=60)
    slug = models.SlugField(max_length=80)
    authors = models.ManyToManyField(Author, related_name='books', blank=False)
    isbn = ISBNField()
    image = models.ImageField(upload_to=upload_location, null=True, blank=True)
    price = models.DecimalField(default=0, decimal_places=2, max_digits=10)
    publish_date = models.DateField(default=date.today, blank=True)
    created = models.DateTimeField(auto_now=True, auto_now_add=False)
    updated = models.DateTimeField(auto_now=False, auto_now_add=True)
    active = models.BooleanField(default=True)

    class Meta:
        verbose_name = 'book'
        verbose_name_plural = 'books'

    def __str__(self):
        return '%s' % self.title

    def get_absolute_url(self):
        return reverse('books:book_detail',
                       kwargs={
                           'slug': self.slug,
                           'pk': self.pk
                       })
예제 #3
0
class Book(models.Model):
	"""
		Model containing informations about books.
		Model is related Author model (ForeignKey) and
		has reverse relation with Opinions model (M2M). 
	"""
	title 			= models.CharField(max_length=100) 
	genre 			= models.CharField(max_length=30)
	ISBN 			= ISBNField(unique=True)
	author 			= models.ForeignKey(
						Author, 
						on_delete=models.SET_NULL, 
						null=True, default=None
					) 

	def __str__(self):
		return f"{self.title}- {self.ISBN}"
	
	@property
	@zero_division_handling
	def general_rating(self):
		book = Book.objects.get(pk=self.pk)
		total_rates = 0
		for op in book.opinions.all():
			total_rates += op.rating
		total_rates = round(total_rates/ book.opinions.all().count(), 1)
		return total_rates	

	class Meta:
		ordering = ["pk"]
예제 #4
0
class Book(models.Model):
    isbn = ISBNField(unique=True, blank=True, null=True)
    title = models.CharField(max_length=256, blank=True, null=True)
    subject = models.ForeignKey('BookSubject',
                                max_length=64,
                                blank=True,
                                null=True)
    edition = models.PositiveSmallIntegerField(blank=True, null=True)
    description = models.CharField(max_length=64, blank=True, null=True)
    editorial = models.ForeignKey('Editorial', blank=True, null=True)
    num_pages = models.PositiveIntegerField(blank=True, null=True)
    condition = models.ForeignKey('BookCondition', blank=True, null=True)
    extra = models.CharField(max_length=256, blank=True, null=True)
    index = JSONField(blank=True, null=True)

    @property
    def matter(self):
        return str(self.subject.matter)

    def author_list(self):
        author_list = self.authors.all()
        str_author_list = ', '.join([a.name for a in author_list])
        return str_author_list

    author_list.short_description = "Authors"

    def __str__(self):
        return self.title

    class Meta:
        db_table = 'book'
예제 #5
0
class Book(models.Model):
    """
        Class representing Book database table.
    """
    class Meta:
        db_table = 'books__book'
        ordering = ['id']

    # Attributes
    id = models.AutoField(primary_key=True)

    title = models.CharField(max_length=255)

    isbn = ISBNField(unique=True)

    price = models.DecimalField(max_digits=6, decimal_places=2, default=0)

    short_description = models.TextField(blank=True, null=True)

    # Relations

    # As of Django 1.11, get_user_model can now be called at import time, even in modules that define models.
    author = models.ForeignKey(get_user_model(),
                               blank=True,
                               null=True,
                               on_delete=models.CASCADE)

    # Properties
    @property
    def currency(self):
        return "{0}".format(settings.USED_CURRENCY)
예제 #6
0
class Book(CatalogueMixin):
    """
    Model representing a book (but not a specific copy of a book).
    """
    author = models.ManyToManyField(
        Author,
        related_name='books',
        related_query_name='book',
    )

    summary = models.TextField(max_length=1000)
    
    isbn = ISBNField(unique=True)

    # ManyToManyField used because genre can contain many books.
    # Books can cover many genres.
    # Genre class has already been defined so we can specify the object above.
    genre = models.ManyToManyField(
        Genre,
        related_name='books',
        related_query_name='book'
    )

    class Meta:
        verbose_name = _('book')
        verbose_name_plural = _('books')
    
    class JSONAPIMeta:
        resource_name = 'books'
예제 #7
0
파일: models.py 프로젝트: rogemus/BookHub
class Book(models.Model):
    id = models.UUIDField(primary_key=True,
                          default=uuid.uuid4,
                          editable=False,
                          verbose_name='catalogue number')
    title = models.CharField(db_index=True, max_length=100)
    authors = models.ManyToManyField(Author)
    publisher = models.ForeignKey(Publisher, on_delete=models.CASCADE)
    description = models.TextField()
    publication_date = models.DateField()
    image_url = models.URLField()
    cover = models.CharField(max_length=9,
                             choices=COVER_TYPES_CHOICES,
                             default='paperback')
    language = models.CharField(max_length=2,
                                choices=BOOK_LANGUAGE_CHOICES,
                                default='PL')
    isbn = ISBNField(db_index=True)

    def get_last_comments(self, qt=settings.BOOK_LAST_COMMENTS):
        return self.comments.filter(
            is_removed=False, is_public=True).order_by('-submit_date')[:qt]

    def __str__(self):
        return self.title
예제 #8
0
class Book(models.Model):
    title = models.CharField(max_length=64, blank=None)
    author = models.ForeignKey(Author, on_delete=models.CASCADE)
    year = models.SmallIntegerField(blank=True)
    category = models.IntegerField(choices=BOOK_CATEGORY, default=2)
    description = models.TextField(blank=True)
    isbn = ISBNField(blank=True)
    dirty_isbn = ISBNField(clean_isbn=False)
    available = models.IntegerField(choices=AVAILABLE, default=8)

    @property
    def book_title(self):
        return "{} {} {} rok wydania {}".format(self.author, self.title,
                                                self.year)

    def __str__(self):
        return self.book_title
예제 #9
0
파일: models.py 프로젝트: Raghaadmr/Library
class Book(models.Model):
    name = models.CharField(max_length=120)
    author = models.CharField(max_length=120)
    year_of_release = models.PositiveIntegerField(default=datetime.date.today().year, validators=[MinValueValidator(1100),MaxValueValidator(datetime.date.today().year)])
    isbn = ISBNField(clean_isbn=False)
    genre = models.CharField(max_length=100)
    borrowed = models.BooleanField(default=False)
    cover = models.ImageField(null=True, blank=True)
예제 #10
0
class BookStore(models.Model):
    title = models.CharField(max_length=10, default=True)
    author = models.CharField(max_length=10, default=True)
    isbn = ISBNField(default=True)
    publication = models.CharField(max_length=255, default=True)
    created_on = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title
예제 #11
0
class Book(models.Model):
    title=models.CharField( max_length=250)
    author=models.CharField(max_length=100)
    author=models.ForeignKey(User,null=True,on_delete=models.CASCADE,related_name="Book")
    categories=models.ManyToManyField(Category)
    isbn = ISBNField(verbose_name=_('ISBN code'))
    

    def __str__(self):
        return self.title
예제 #12
0
class Book(models.Model):
    """
    Book model describes book object in main app.
    """
    isbn = ISBNField(primary_key=True)
    name = models.CharField(max_length=255, verbose_name=gettext_lazy("Name"))
    authors = models.CharField(max_length=255,
                               verbose_name=gettext_lazy("Authors"))
    added_date = models.DateTimeField(auto_now_add=True,
                                      verbose_name=gettext_lazy("Added date"))
    count = models.PositiveSmallIntegerField(
        verbose_name=gettext_lazy("Count"))

    def __str__(self):
        return "{} [{}]".format(self.name, self.authors)

    def formatted_isbn(self):
        """
        Returns ISBN in proper format woth dashes.
        """
        return isbn.format(self.isbn)

    def truncated_name(self):
        """
        Returns shortened name for displaying in lists and cards.
        """
        if len(self.name) <= 100:
            return self.name

        short_name = self.name[:100]
        words = short_name.split(' ')[:-1]

        return ' '.join(words) + '…'

    def is_active(self):
        """
        Returns True if count is greater than 0. Otherwise returns
        False.
        """
        return self.count > 0

    def available_count(self):
        """
        Returns count - leased books count.
        """
        return max(
            self.count -
            self.lease_set.filter(return_date__isnull=True).count(), 0)

    def is_available(self):
        """
        Returns True if self.available_count() is greater than 0.
        Otherwise returns False.
        """
        return self.count > 0 and self.available_count() > 0
예제 #13
0
class Book(models.Model):
    title = models.CharField(max_length=255)
    author_info = models.TextField()
    isbn = ISBNField()
    price = models.DecimalField(decimal_places=2, max_digits=5)
    publish_date = models.DateTimeField(default=datetime.date.today)
    updated_at = models.DateTimeField(auto_now=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title
예제 #14
0
class Publication(models.Model):
    creator = models.ForeignKey('auth.User',
                                related_name='publications',
                                on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    author = models.CharField(blank=True, max_length=255)
    year = models.PositiveSmallIntegerField(blank=True, null=True)
    isbn = ISBNField(blank=True, max_length=255)

    def __str__(self):
        """A string representation of the model."""
        return self.title
예제 #15
0
class Book(models.Model):
    name = models.CharField(_('Name'), max_length=255)
    isbn = ISBNField(_('ISBN'))
    publish_date = models.DateField(_('Date Created'))
    author = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        verbose_name = _('Book')
        verbose_name_plural = _('Books')

    def __str__(self):
        return f'{self.name} {self.isbn} Author: {self.author}'
예제 #16
0
class BookForm(forms.ModelForm):
    title = forms.CharField()
    publication_date = forms.CharField()
    authors = forms.ModelMultipleChoiceField(Author.objects.all())
    ISBN = ISBNField()
    pages = forms.IntegerField()
    language = forms.CharField()

    
    class Meta:
        model = Book
        fields = ["title", "publication_date", "authors", "ISBN", "pages", "language"]
예제 #17
0
파일: models.py 프로젝트: alexkimeu/Libre
class Book(models.Model):
    member = models.ForeignKey(Member, on_delete=models.PROTECT, default=1)
    title = models.CharField(max_length=100)
    author = models.CharField(max_length=65)
    publisher = models.CharField(max_length=100)
    year = models.CharField(max_length=4)
    borrowed = models.DateTimeField(default=timezone.now)
    isbn = ISBNField()
    duration = models.DurationField()
    returned = models.BooleanField(default=0)

    def __str__(self):
        return self.title
예제 #18
0
class Book(models.Model):
    book_name = models.CharField(max_length=120)
    image = models.ImageField(upload_to='bookpic', null=True, blank=True)
    conditions = (
        ('New', 'New'),
        ('Used', 'Used'),
    )
    condition = models.CharField(
        max_length=5,
        choices=conditions,
        default='New',
    )
    isbn = ISBNField(clean_isbn=False)
    author = models.CharField(max_length=120)

    def __str__(self):
        return "%s by %s" % (self.book_name, self.author)
예제 #19
0
class Book(models.Model):
    isbn = ISBNField()
    title = models.CharField(max_length=100)
    date_of_release = models.DateField(null=True, blank=True)
    authors = models.ManyToManyField(Author, blank=True)
    categories = models.ManyToManyField(Category, blank=True)
    on_loan_to = models.ForeignKey('clients.Client',
                                   on_delete=models.SET_NULL,
                                   null=True,
                                   blank=True)

    # owned_by : ForeignKey Library

    def __repr__(self):
        return "Book(isbn='{}', title='{}')".format(self.isbn, self.title)

    def __str__(self):
        return '{} - {}'.format(self.title, self.date_of_release)
예제 #20
0
class Book(models.Model):

    title = models.CharField(max_length=100)    
    publication_date = models.CharField(validators=[date_validator,], max_length=10)
    authors = models.ManyToManyField("Author", related_name="author")
    ISBN = ISBNField() #validators=[book_unique_validator,]
    pages = models.IntegerField(validators=[page_validator,], blank=True)
    language = models.CharField(max_length=4)

    def __str__(self):
        return self.title

    def get_all_authors(self):
        return "".join([x.name.title() +", " for x in self.authors.all()])[:-2]


    class Meta:
        ordering = ["title"] 
예제 #21
0
class Book(models.Model):
    """
    Model representing a book (but not a specific copy of book).
    """
    title = models.CharField(max_length=200)
    author = models.ForeignKey('Author', on_delete=models.SET_NULL, null=True)
    # ForeignKey used because book can only have one author, but authors can have multiple books
    # Author as a string rather than object because it hasn't been declared yet in the file.
    summary = models.TextField(
        max_length=2000, help_text="Enter a brief description of the book")
    isbn = ISBNField(
        clean_isbn=False,
        help_text=
        '13 Character <a href="https://www.isbn-international.org/content/what-isbn">ISBN number</a>'
    )
    genre = models.ManyToManyField(Genre,
                                   help_text="Select a genre for this book")
    # ManyToManyField used because genre can contain many books. Book can cover many genres.
    # Genre class has already been defined so we can specify the object above.
    language = models.ForeignKey('Language',
                                 on_delete=models.SET_NULL,
                                 null=True,
                                 blank=True)

    def __str__(self):
        """
        String for representing the Model object.
        """
        return self.title

    def get_absolute_url(self):
        """
        Return the url to access a particular book instance.
        """
        return reverse('book-detail', args=[str(self.id)])

    def display_genre(self):
        """
        Creates a sting for the Genre. This is required for display genre in Admin
        """
        return ', '.join([genre.name for genre in self.genre.all()[:3]])

    class Meta:
        ordering = ['pk']
예제 #22
0
class Libro(Model):
    autores = models.ManyToManyField(Autor, related_name="autores_de_libros")
    coleccion = models.ManyToManyField(Coleccion)
    titulo = models.CharField("Titulo", max_length=500)
    isbn = ISBNField("ISBN", blank=True, null=True)
    texto = tinymce_models.HTMLField("Texto")
    indice = tinymce_models.HTMLField("Indice", blank=True, null=True)

    imagen = VersatileImageField('Foto',
                                 upload_to=libro_filename,
                                 blank=True,
                                 null=True)
    fecha = models.DateField("Fecha publicación", null=True, blank=True)

    campo1 = models.PositiveSmallIntegerField("Campo 1",
                                              default=2,
                                              choices=CAMPOS)
    prologo = models.CharField("Contenido Campo 1",
                               max_length=500,
                               blank=True,
                               null=True)
    campo2 = models.PositiveSmallIntegerField("Campo 2",
                                              default=1,
                                              choices=CAMPOS)
    traductor = models.CharField("Contenido Campo 2",
                                 max_length=500,
                                 blank=True,
                                 null=True)
    campo3 = models.PositiveSmallIntegerField("Campo 3",
                                              default=1,
                                              choices=CAMPOS)
    campo3contenido = models.CharField("Contenido Campo 3",
                                       max_length=500,
                                       blank=True,
                                       null=True)

    descripcion = models.CharField("Descripción (250 chars)",
                                   max_length=250,
                                   blank=True,
                                   null=True)
    subtitulo = models.CharField("Sub Titulo",
                                 max_length=500,
                                 blank=True,
                                 null=True)
    recomendado = models.BooleanField("Recomendado", default=False)
    disponible = models.BooleanField("Disponible", default=True)

    paginas = models.PositiveIntegerField("Páginas", blank=True, null=True)
    formato = models.CharField("Formato",
                               max_length=20,
                               choices=FORMATOS,
                               blank=True,
                               null=True)
    edicion = models.PositiveSmallIntegerField("Edición",
                                               choices=EDICIONES,
                                               blank=True,
                                               null=True)
    carrito = models.URLField("URL Carrito de compras", null=True, blank=True)
    pdf = models.FileField("PDF",
                           upload_to='uploads/pdf/',
                           null=True,
                           blank=True)

    tags = TaggableManager(blank=True)

    class Meta:
        verbose_name_plural = "Libros"
        ordering = [
            '-fecha',
            '-id',
        ]

    def get_absolute_url(self):
        return reverse("libro", args=[self.id, slugify(self.titulo)])

    def get_autores(self):
        return " ".join([str(a) for a in self.autores.all()])

    def get_colecciones(self):
        return " ".join([str(a) for a in self.coleccion.all()])

    def __str__(self):
        return self.titulo

    @property
    def fISBN(self):
        i = self.isbn
        try:
            if len(i) > 10:
                return "%s-%s-%s-%s-%s" % (i[0:3], i[3:6], i[6:10], i[10:12],
                                           i[12])
            else:
                return "%s-%s-%s-%s" % (i[0], i[1:3], i[3:9], i[9])
        except (IndexError, TypeError):
            return i

    def imagen_html_sized(self, size='90x120'):
        try:
            return mark_safe("<img src='%s' alt='%s' />" %
                             (self.imagen.thumbnail[size].url, self))
        except:
            pass
        return ""

    imagen_html_sized.short_description = "Thumbnail"

    def imagen_html(self):
        try:
            return mark_safe("<img src='%s' alt='%s' />" %
                             (self.imagen.url, self))
        except:
            pass
        return ""

    imagen_html.short_description = "Muestra de la imagen"
예제 #23
0
class Book(models.Model):
    ISBN = ISBNField(primary_key=True)
    title = models.CharField(max_length=256)
    description = models.CharField(max_length=256)
    price = models.DecimalField(decimal_places=2,max_digits=8)
    author = models.CharField(max_length=256)
예제 #24
0
class DirtyISBNModel(models.Model):

    isbn = ISBNField(clean_isbn=False)
예제 #25
0
class UniqueCleanISBNModel(models.Model):

    isbn = ISBNField(unique=True) # clean_isbn=True (default)
예제 #26
0
class CleanISBNModel(models.Model):
    id = models.BigAutoField(primary_key=True)
    isbn = ISBNField() # clean_isbn=True (default)
예제 #27
0
class BlankNullISBNModel(models.Model):
    id = models.BigAutoField(primary_key=True)
    isbn = ISBNField(clean_isbn=True, blank=True, null=True)
예제 #28
0
class BlankNullISBNModel(models.Model):

    isbn = ISBNField(clean_isbn=True, blank=True, null=True)
예제 #29
0
class DirtyISBNModel(models.Model):
    id = models.BigAutoField(primary_key=True)
    isbn = ISBNField(clean_isbn=False)
예제 #30
0
class CleanISBNModel(models.Model):

    isbn = ISBNField()  # clean_isbn=True (default)