-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Uproszczenie panelu administracyjnego w app. Django "Mały Bar – Pizza"
- Loading branch information
Showing
1 changed file
with
3 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,7 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import Pizza, Skladnik | ||
from django.forms import Textarea | ||
from django.db import models | ||
|
||
|
||
class SkladnikInline(admin.TabularInline): | ||
model = Skladnik | ||
max_num = 6 | ||
extra = 3 | ||
fields = ['nazwa', 'jarski'] | ||
|
||
|
||
class PizzaAdmin(admin.ModelAdmin): | ||
# fields = ['przedmiot', 'kategoria', 'typ', 'polecenie'] | ||
exclude = ('autor',) | ||
# obiekty zależne do wyświetlenia | ||
inlines = [SkladnikInline] | ||
# nagłówki do wyświetlenia | ||
# list_display = ('question_text', 'pub_date', 'was_published_recently') | ||
# wyszukiwanie | ||
search_fields = ['nazwa'] | ||
list_per_page = 10 | ||
|
||
formfield_overrides = { | ||
models.TextField: {'widget': Textarea(attrs={'rows': 2, 'cols': 100})}, | ||
} | ||
|
||
def save_model(self, request, obj, form, change): | ||
if not change: | ||
obj.autor = request.user | ||
obj.save() | ||
|
||
|
||
# rejestrujemy model Pizza w panelu administracyjnym | ||
admin.site.register(Pizza, PizzaAdmin) | ||
# rejestrujemy modele w panelu administracyjnym | ||
admin.site.register(Pizza) | ||
admin.site.register(Skladnik) |