init
This commit is contained in:
0
books/__init__.py
Normal file
0
books/__init__.py
Normal file
30
books/admin.py
Normal file
30
books/admin.py
Normal file
@@ -0,0 +1,30 @@
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import Book, Author
|
||||
|
||||
admin.site.site_header = "Moje Centrum Zarządzania" # Nagłówek na górze strony admina
|
||||
admin.site.site_title = "Panel admina - Moja Aplikacja" # Tytuł strony (np. zakładki przeglądarki)
|
||||
admin.site.index_title = "Witamy w panelu administracyjnym" # Nagłówek na stronie głównej po zalogowaniu
|
||||
|
||||
class BookAdmin(admin.ModelAdmin):
|
||||
list_display = ('title', 'author')
|
||||
search_fields = ('title', 'author__name')
|
||||
list_filter = ('author',)
|
||||
ordering = ['title']
|
||||
fields = ['title', 'author']
|
||||
readonly_fields = ('id',)
|
||||
|
||||
#admin.site.register(Book)
|
||||
#admin.site.register(Author)
|
||||
|
||||
admin.site.register(Book, BookAdmin)
|
||||
|
||||
class BookInline(admin.TabularInline):
|
||||
model = Book
|
||||
extra = 1
|
||||
|
||||
class AuthorAdmin(admin.ModelAdmin):
|
||||
inlines = [BookInline]
|
||||
|
||||
admin.site.register(Author, AuthorAdmin)
|
||||
6
books/apps.py
Normal file
6
books/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class BooksConfig(AppConfig):
|
||||
default_auto_field = 'django.db.models.BigAutoField'
|
||||
name = 'books'
|
||||
31
books/migrations/0001_initial.py
Normal file
31
books/migrations/0001_initial.py
Normal file
@@ -0,0 +1,31 @@
|
||||
# Generated by Django 5.2 on 2025-04-07 15:44
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
initial = True
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Author',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
],
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='Book',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('title', models.CharField(max_length=200)),
|
||||
('active', models.BooleanField(default=True)),
|
||||
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='books.author')),
|
||||
],
|
||||
),
|
||||
]
|
||||
0
books/migrations/__init__.py
Normal file
0
books/migrations/__init__.py
Normal file
24
books/models.py
Normal file
24
books/models.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
||||
class Author(models.Model):
|
||||
name = models.CharField(max_length=100, verbose_name="Imię i nazwisko")
|
||||
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Autor"
|
||||
verbose_name_plural = "Autorzy"
|
||||
|
||||
class Book(models.Model):
|
||||
title = models.CharField(max_length=200, verbose_name="Tytuł")
|
||||
active = models.BooleanField(default=True, verbose_name="Aktywny")
|
||||
author = models.ForeignKey(Author, on_delete=models.CASCADE, verbose_name="Autor") # (PROTECT, SET_NULL, RESTRICT).
|
||||
|
||||
def __str__(self):
|
||||
return self.title
|
||||
|
||||
class Meta:
|
||||
verbose_name = "Książka"
|
||||
verbose_name_plural = "Książki"
|
||||
3
books/tests.py
Normal file
3
books/tests.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
||||
3
books/views.py
Normal file
3
books/views.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.shortcuts import render
|
||||
|
||||
# Create your views here.
|
||||
Reference in New Issue
Block a user