Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Prodavnica za zdrava hrana auf od juni '22 ispit
- ----------------------------models.py------------------------------------
- from django.db import models
- from django.contrib.auth.models import User
- # Create your models here.
- class Kategorija(models.Model):
- ime = models.CharField(max_length=50)
- opis = models.CharField(max_length=50)
- daliAktivna = models.BooleanField(default=False)
- class Klient(models.Model):
- ime = models.CharField(max_length=50)
- prezime = models.CharField(max_length=50)
- adresa = models.CharField(max_length=50)
- email = models.CharField(max_length=50)
- class Produkt(models.Model):
- sifra = models.AutoField(primary_key=True)
- ime = models.CharField(max_length=50)
- opis = models.CharField(max_length=50)
- kategorija = models.ForeignKey(Kategorija,models.CASCADE)
- korisnik = models.ForeignKey(User, on_delete=models.CASCADE)
- fotografija = models.ImageField(upload_to='sliki/', null=True, blank=True)
- cena = models.IntegerField()
- kolicina = models.IntegerField()
- class Prodazba(models.Model):
- produkt = models.ForeignKey(Produkt,models.CASCADE)
- kolicina = models.IntegerField()
- datum = models.DateField()
- klient = models.ForeignKey(Klient,models.CASCADE)
- ----------------------------admin.py------------------------------------
- from django.contrib import admin
- from .models import Produkt,Prodazba,Kategorija,Klient
- # Register your models here.
- class ProduktInline(admin.StackedInline):
- model = Produkt
- extra = 1
- class KategorijaAdmin(admin.ModelAdmin):
- list_display = ('ime',)
- def has_delete_permission(self, request, obj=None):
- if obj and obj.korisnik==request.user.is_superuser:
- return True
- return False
- class KlientAdmin(admin.ModelAdmin):
- list_display = ('ime','prezime',)
- class ProduktAdmin(admin.ModelAdmin):
- exclude = ("korisnik",)
- def save_model(self, request, obj, form, change):
- obj.korisnik = request.user
- super().save_model(request, obj, form, change)
- def has_change_permission(self, request, obj=None):
- if obj and obj.korisnik == request.user:
- return True
- return False
- def has_delete_permission(self, request, obj=None):
- return False
- admin.site.register(Produkt, ProduktAdmin)
- admin.site.register(Kategorija, KategorijaAdmin)
- admin.site.register(Prodazba)
- admin.site.register(Klient,KlientAdmin)
- ----------------------------settings.py------------------------------------
- INSTALLED_APPS = [
- 'django.contrib.admin',
- 'django.contrib.auth',
- 'django.contrib.contenttypes',
- 'django.contrib.sessions',
- 'django.contrib.messages',
- 'django.contrib.staticfiles',
- 'HealthyApp',
- ]
- STATIC_URL = 'static/'
- MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
- MEDIA_URL = '/media/'
- ----------------------------urls.py------------------------------------
- from django.contrib import admin
- from django.urls import path
- from django.conf.urls.static import static
- from django.conf import settings
- from HealthyApp.views import index, outOfStock
- urlpatterns = [
- path('admin/', admin.site.urls),
- path('index/', index, name='index.html',),
- path('outOfStock/', outOfStock, name='outOfStock.html',),
- ] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
- ----------------------------views.py------------------------------------
- def outOfStock(request):
- if request.method == "POST":
- form = ProduktForm(request.POST, request.FILES)
- if form.is_valid():
- produkt = form.save(commit=False)
- produkt.korisnik = request.user
- produkt.fotografija = form.cleaned_data['fotografija']
- produkt.save()
- return redirect("outOfStock.html")
- queryset = Produkt.objects.filter(kolicina=0).filter(kategorija__daliAktivna=True).all()
- context = {'produkts': queryset, 'form': ProduktForm}
- return render(request, 'outOfStock.html', context=context)
- def index(request):
- return render(request, 'index.html')
- ----------------------------forms.py------------------------------------
- class ProduktForm(forms.ModelForm):
- def __init__(self, *args, **kwargs):
- super(ProduktForm, self).__init__(*args, **kwargs)
- for field in self.visible_fields():
- field.field.widget.attrs['class'] = "form-control"
- class Meta:
- model = Produkt
- exclude = ['korisnik', ]
- ----------------------------templates------------------------------------
- <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
- <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
- ----------------------------index.html------------------------------------
- <div class="container" style="padding-top: 10px; margin-top: 30px;" >
- <div class="row" style="justify-content: center">
- <div class="col-md-4" >
- <div class="d-flex align-items-start">
- <div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist" aria-orientation="vertical">
- <ul style="list-style: none; border: solid black 3px; text-align: center" >
- <li class="nav-item dropdown nav-link btn btn-success">
- <a class="nav-link dropdown-toggle" data-bs-toggle="dropdown" href="#" role="button" aria-expanded="false" style="color:white; background-color: green">All Departments</a>
- <ul class="dropdown-menu">
- <li><a class="dropdown-item" href="#">Action</a></li>
- <li><a class="dropdown-item" href="#">Another action</a></li>
- <li><a class="dropdown-item" href="#">Something else here</a></li>
- <li><hr class="dropdown-divider"></li>
- <li><a class="dropdown-item" href="#">Separated link</a></li>
- </ul>
- </li>
- <li style="padding-top: 20px">
- Fruits
- </li>
- <li style="text-align: center;padding-top: 20px">
- Fruits
- </li>
- <li style="text-align: center;padding-top: 20px">
- Fruits
- </li>
- <li style="text-align: center;padding-top: 20px">
- Fruits
- </li>
- <li style="text-align: center;padding-top: 20px">
- Fruits
- </li>
- <li style="text-align: center;padding-top: 20px">
- Fruits
- </li>
- </ul>
- </div>
- </div>
- </div>
- <div class="col-md-8" style="background-image: url('https://images.unsplash.com/photo-1490818387583-1baba5e638af?q=80&w=1932&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D')">
- <div class="row" style="justify-content: center">
- <div class="col-md-6">
- </div>
- <div class="col-md-6" style="margin-top: 50px; margin-bottom: 50px">
- <h6 class="display-6">Fruit Fresh</h6>
- <h1 class="display-3">Vegetable</h1>
- <h1 class="display-3">100% Organic</h1>
- <p style="color: gray">Free Pickup and Delivery Available</p>
- <div style="text-align: center; margin-top: 20px">
- <button class="btn btn-success">Shop Now</button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- <div style="text-align: center;margin-top: 50px;">
- <h1 class="display-4">From The Blog</h1>
- <h3 style="color: green; font-weight: bolder">---------</h3>
- </div>
- <div class="container" style="padding-top: 10px; margin-top: 40px">
- <div class="row" style="justify-content: center">
- <div class="col-md-4 card mb-4" >
- <div class="card" >
- <div style="text-align: center; background: url('https://plus.unsplash.com/premium_photo-1675731118330-08c71253af17?q=80&w=1854&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); color: white; height: 300px; width: 420px" >
- </div>
- <div class="card-body" style="text-align: left; background-color: white; color: black">
- <p style="margin-top: 20px; font-size: 25px;">May 16 2024</p>
- <h3
- style="margin-top: 20px">Vasina Cake</h3>
- <p style="margin-top: 20px; font-size: 25px;">Potrebni ni se 6 jajca i pritoa gi delime zolckite od belkite...</p>
- </div>
- </div>
- </div>
- <div class="col-md-4 card mb-4" >
- <div class="card" >
- <div style="text-align: center; background: url('https://plus.unsplash.com/premium_photo-1675731118330-08c71253af17?q=80&w=1854&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); color: white; height: 300px; width: 420px" >
- </div>
- <div class="card-body" style="text-align: left; background-color: white; color: black">
- <p style="margin-top: 20px; font-size: 25px;">May 16 2024</p>
- <h3
- style="margin-top: 20px">Vasina Cake</h3>
- <p style="margin-top: 20px; font-size: 25px;">Potrebni ni se 6 jajca i pritoa gi delime zolckite od belkite...</p>
- </div>
- </div>
- </div>
- <div class="col-md-4 card mb-4" >
- <div class="card" >
- <div style="text-align: center; background: url('https://plus.unsplash.com/premium_photo-1675731118330-08c71253af17?q=80&w=1854&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D'); color: white; height: 300px; width: 420px" >
- </div>
- <div class="card-body" style="text-align: left; background-color: white; color: black">
- <p style="margin-top: 20px; font-size: 25px;">May 16 2024</p>
- <h3
- style="margin-top: 20px">Vasina Cake</h3>
- <p style="margin-top: 20px; font-size: 25px;">Potrebni ni se 6 jajca i pritoa gi delime zolckite od belkite...</p>
- </div>
- </div>
- </div>
- </div>
- </div>
- <footer class="bg-info" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
- <div class="container" style="margin-top: 30px; margin-bottom:30px">
- <div class="row" style="justify-content: center">
- <div class="col-md-4" >
- <h5>FINKI EXAM</h5>
- <p>Sveti Nikole</p>
- <p>Sveti Nikole</p>
- <p>Sveti Nikole</p>
- </div>
- <div class="col-md-4" >
- <h5>FINKI EXAM</h5>
- <p>Sveti Nikole</p>
- <p>Sveti Nikole</p>
- <p>Sveti Nikole</p>
- </div>
- <div class="col-md-4" >
- <h5>FINKI EXAM</h5>
- <p>Sveti Nikole</p>
- <p>Sveti Nikole</p>
- <p>Sveti Nikole</p>
- </div>
- </div>
- </div>
- </footer>
- </body>
- ----------------------------outOfStock.html------------------------------------
- <body>
- <div style="text-align: center;margin-top: 50px;">
- <h1 class="display-4">Out Of Stock</h1>
- <h3 style="color: green; font-weight: bolder">---------</h3>
- </div>
- <div class="container" style="padding-top: 40px;">
- <div class="row" style="justify-content: center">
- {% for produkt in produkts %}
- <div class="col-md-3 card mb-3" style="max-width: 18rem;">
- <div class="card" style="width: 18rem;" >
- <img src= "{{ MEDIA_URL }} {{ produkt.fotografija.url }}" alt="...">
- <div class="card-body " style="text-align: center">
- <h4 class="card-title"><b> {{produkt.ime}}</b></h4>
- <h5 class="card-title">${{produkt.cena}}</h5>
- <p>{{produkt.opis}}</p>
- </div>
- </div>
- </div>
- {% endfor %}
- </div>
- </div>
- <div class="container" style="padding: 20px; background-color: whitesmoke; box-shadow: black; margin-top: 40px">
- <form method="post" enctype="multipart/form-data">
- {% csrf_token %}
- {{ form.as_p }}
- <button class="btn btn-primary" type="submit">Submit</button>
- </form>
- </div>
- <footer class="bg-info" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
- <div class="container" style="margin-top: 30px; margin-bottom:30px">
- <div class="row" style="justify-content: center">
- <div class="col-md-4" >
- <h5>FINKI EXAM</h5>
- <p>Organisation</p>
- <p>Organisation</p>
- <p>Organisation</p>
- </div>
- <div class="col-md-4" >
- <h5>FINKI EXAM</h5>
- <p>Organisation</p>
- <p>Organisation</p>
- <p>Organisation</p>
- </div>
- <div class="col-md-4" >
- <h5>FINKI EXAM</h5>
- <p>Organisation</p>
- <p>Organisation</p>
- <p>Organisation</p>
- </div>
- </div>
- </div>
- </footer>
- </body>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement