Advertisement
Emefpe

Księgozbiór - models.py

May 9th, 2018
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.03 KB | None | 0 0
  1. from django.db import models
  2. from django.contrib.auth.models import User
  3.  
  4.  
  5. class Autor(models.Model):
  6.     imie = models.CharField(max_length=100, verbose_name="Imię")
  7.     nazwisko = models.CharField(max_length=100)
  8.  
  9.     class Meta:
  10.         ordering = ['nazwisko', 'imie']
  11.         verbose_name_plural = 'Autorzy'
  12.  
  13.     def __str__(self):
  14.         return "{}, {}".format(self.nazwisko, self.imie)
  15.  
  16.  
  17. class Wydawnictwo(models.Model):
  18.     nazwa = models.CharField(max_length=200)
  19.  
  20.     class Meta:
  21.         ordering = ['nazwa']
  22.         verbose_name_plural = 'Wydawnictwa'
  23.  
  24.     def __str__(self):
  25.         return self.nazwa
  26.  
  27.  
  28. class Wypozyczajacy(models.Model):
  29.     imie = models.CharField(max_length=100, verbose_name='Imię')
  30.     nazwisko = models.CharField(max_length=100)
  31.     telefon = models.CharField(max_length=50, blank=True, null=True)
  32.     email = models.EmailField(blank=True, null=True, verbose_name='E-mail')
  33.  
  34.     class Meta:
  35.         ordering = ['nazwisko', 'imie']
  36.         verbose_name_plural = 'Wypożyczający'
  37.  
  38.     def __str__(self):
  39.         return "{}, {}".format(self.nazwisko, self.imie)
  40.  
  41.  
  42. class Ksiazka(models.Model):
  43.     tytul = models.CharField(max_length=200, verbose_name='Tytuł', help_text='pole wymagane')
  44.    
  45.     # PROBLEM
  46.     autor = models.ForeignKey(Autor)
  47.    
  48.     wydawnictwo = models.ForeignKey(Wydawnictwo)
  49.     wydanie = models.CharField(max_length=10, null=True, blank=True)
  50.     rok_wydania = models.CharField(max_length=10, null=True, blank=True)
  51.     wypozyczajacy = models.ForeignKey(Wypozyczajacy, null=True, blank=True)
  52.     data_wypozyczenia = models.DateField(null=True, blank=True)
  53.     data_wpisu = models.DateTimeField(auto_now_add=True)
  54.     ostatnia_aktualizacja = models.DateTimeField(auto_now=True)
  55.  
  56.     STATUS = (
  57.         ('d', 'w domu'),
  58.         ('w', 'wypożyczona')
  59.     )
  60.  
  61.     status = models.CharField(max_length=1, choices=STATUS, default='d')
  62.  
  63.     class Meta:
  64.         ordering = ['tytul']
  65.         verbose_name_plural = 'Książki'
  66.  
  67.     def __str__(self):
  68.         return self.tytul
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement