Added some logic
This commit is contained in:
@@ -1,3 +1,19 @@
|
||||
from django.db.models import Q, F
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
from apps.books.models import Book
|
||||
from apps.shelves.models import Shelf
|
||||
|
||||
class ShelfItem(models.Model):
|
||||
book = models.ForeignKey(Book, on_delete=models.CASCADE, related_name="shelf_items")
|
||||
shelf = models.ForeignKey(Shelf, on_delete=models.CASCADE, related_name="book_items")
|
||||
|
||||
quantity = models.PositiveIntegerField(default=0)
|
||||
|
||||
class Meta:
|
||||
constraints = [
|
||||
models.UniqueConstraint(
|
||||
fields=["book", "shelf"],
|
||||
name="unique_book_per_shelf"
|
||||
),
|
||||
]
|
||||
Reference in New Issue
Block a user