Advertisement
dzocesrce

[DNICK] Healthy Food Store

Jun 7th, 2024
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.58 KB | None | 0 0
  1. # Prodavnica za zdrava hrana auf od juni '22 ispit
  2.  
  3. ----------------------------models.py------------------------------------
  4.  
  5. from django.db import models
  6. from django.contrib.auth.models import User
  7. # Create your models here.
  8.  
  9.  
  10. class Kategorija(models.Model):
  11.     ime = models.CharField(max_length=50)
  12.     opis = models.CharField(max_length=50)
  13.     daliAktivna = models.BooleanField(default=False)
  14.  
  15. class Klient(models.Model):
  16.     ime = models.CharField(max_length=50)
  17.     prezime = models.CharField(max_length=50)
  18.     adresa = models.CharField(max_length=50)
  19.     email = models.CharField(max_length=50)
  20.  
  21. class Produkt(models.Model):
  22.     sifra = models.AutoField(primary_key=True)
  23.     ime = models.CharField(max_length=50)
  24.     opis = models.CharField(max_length=50)
  25.     kategorija = models.ForeignKey(Kategorija,models.CASCADE)
  26.     korisnik = models.ForeignKey(User, on_delete=models.CASCADE)
  27.     fotografija = models.ImageField(upload_to='sliki/', null=True, blank=True)
  28.     cena = models.IntegerField()
  29.     kolicina = models.IntegerField()
  30.  
  31. class Prodazba(models.Model):
  32.     produkt = models.ForeignKey(Produkt,models.CASCADE)
  33.     kolicina = models.IntegerField()
  34.     datum = models.DateField()
  35.     klient = models.ForeignKey(Klient,models.CASCADE)
  36.  
  37.  
  38. ----------------------------admin.py------------------------------------
  39.  
  40. from django.contrib import admin
  41. from .models import Produkt,Prodazba,Kategorija,Klient
  42.  
  43. # Register your models here.
  44.  
  45. class ProduktInline(admin.StackedInline):
  46.     model = Produkt
  47.     extra = 1
  48.  
  49. class KategorijaAdmin(admin.ModelAdmin):
  50.     list_display = ('ime',)
  51.     def has_delete_permission(self, request, obj=None):
  52.         if obj and obj.korisnik==request.user.is_superuser:
  53.             return True
  54.         return False
  55.  
  56. class KlientAdmin(admin.ModelAdmin):
  57.     list_display = ('ime','prezime',)
  58.  
  59. class ProduktAdmin(admin.ModelAdmin):
  60.     exclude = ("korisnik",)
  61.  
  62.     def save_model(self, request, obj, form, change):
  63.         obj.korisnik = request.user
  64.         super().save_model(request, obj, form, change)
  65.  
  66.     def has_change_permission(self, request, obj=None):
  67.         if obj and obj.korisnik == request.user:
  68.             return True
  69.         return False
  70.  
  71.     def has_delete_permission(self, request, obj=None):
  72.         return False
  73.  
  74.  
  75. admin.site.register(Produkt, ProduktAdmin)
  76. admin.site.register(Kategorija, KategorijaAdmin)
  77. admin.site.register(Prodazba)
  78. admin.site.register(Klient,KlientAdmin)
  79.  
  80. ----------------------------settings.py------------------------------------
  81.  
  82. INSTALLED_APPS = [
  83.     'django.contrib.admin',
  84.     'django.contrib.auth',
  85.     'django.contrib.contenttypes',
  86.     'django.contrib.sessions',
  87.     'django.contrib.messages',
  88.     'django.contrib.staticfiles',
  89.     'HealthyApp',
  90. ]
  91. STATIC_URL = 'static/'
  92. MEDIA_ROOT = os.path.join(BASE_DIR,'media/')
  93. MEDIA_URL = '/media/'
  94.  
  95.  
  96. ----------------------------urls.py------------------------------------
  97.  
  98. from django.contrib import admin
  99. from django.urls import path
  100. from django.conf.urls.static import static
  101. from django.conf import settings
  102. from HealthyApp.views import index, outOfStock
  103.  
  104. urlpatterns = [
  105.     path('admin/', admin.site.urls),
  106.     path('index/', index, name='index.html',),
  107.     path('outOfStock/', outOfStock, name='outOfStock.html',),
  108. ] + static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT)
  109.  
  110. ----------------------------views.py------------------------------------
  111.  
  112. def outOfStock(request):
  113.     if request.method == "POST":
  114.         form = ProduktForm(request.POST, request.FILES)
  115.         if form.is_valid():
  116.             produkt = form.save(commit=False)
  117.             produkt.korisnik = request.user
  118.             produkt.fotografija = form.cleaned_data['fotografija']
  119.             produkt.save()
  120.             return redirect("outOfStock.html")
  121.     queryset = Produkt.objects.filter(kolicina=0).filter(kategorija__daliAktivna=True).all()
  122.     context = {'produkts': queryset, 'form':  ProduktForm}
  123.     return render(request, 'outOfStock.html', context=context)
  124.  
  125.  
  126. def index(request):
  127.     return render(request, 'index.html')
  128.  
  129. ----------------------------forms.py------------------------------------
  130.  
  131. class ProduktForm(forms.ModelForm):
  132.     def __init__(self, *args, **kwargs):
  133.         super(ProduktForm, self).__init__(*args, **kwargs)
  134.         for field in self.visible_fields():
  135.             field.field.widget.attrs['class'] = "form-control"
  136.  
  137.     class Meta:
  138.         model = Produkt
  139.         exclude = ['korisnik', ]
  140.        
  141. ----------------------------templates------------------------------------
  142. <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
  143.     <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous"></script>
  144.    
  145. ----------------------------index.html------------------------------------
  146.  
  147. <div class="container" style="padding-top: 10px; margin-top: 30px;" >
  148.     <div class="row" style="justify-content: center">
  149.         <div class="col-md-4" >
  150.          
  151.             <div class="d-flex align-items-start">
  152.   <div class="nav flex-column nav-pills me-3" id="v-pills-tab" role="tablist" aria-orientation="vertical">
  153.       <ul style="list-style: none; border: solid black 3px; text-align: center" >
  154.       <li class="nav-item dropdown nav-link btn btn-success">
  155.     <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>
  156.     <ul class="dropdown-menu">
  157.       <li><a class="dropdown-item" href="#">Action</a></li>
  158.       <li><a class="dropdown-item" href="#">Another action</a></li>
  159.       <li><a class="dropdown-item" href="#">Something else here</a></li>
  160.       <li><hr class="dropdown-divider"></li>
  161.       <li><a class="dropdown-item" href="#">Separated link</a></li>
  162.     </ul>
  163.   </li>
  164.       <li style="padding-top: 20px">
  165.           Fruits
  166.       </li>
  167.       <li style="text-align: center;padding-top: 20px">
  168.           Fruits
  169.       </li>
  170.       <li style="text-align: center;padding-top: 20px">
  171.           Fruits
  172.       </li>
  173.           <li style="text-align: center;padding-top: 20px">
  174.           Fruits
  175.       </li>
  176.       <li style="text-align: center;padding-top: 20px">
  177.           Fruits
  178.       </li>
  179.       <li style="text-align: center;padding-top: 20px">
  180.           Fruits
  181.       </li>
  182.           </ul>
  183.    
  184.   </div>
  185.  
  186. </div>
  187.    
  188.         </div>
  189.         <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')">
  190.        
  191.             <div class="row" style="justify-content: center">
  192.                     <div class="col-md-6">
  193.                     </div>
  194.                     <div class="col-md-6" style="margin-top: 50px; margin-bottom: 50px">
  195.                         <h6 class="display-6">Fruit Fresh</h6>
  196.                         <h1 class="display-3">Vegetable</h1>
  197.                         <h1 class="display-3">100% Organic</h1>
  198.                         <p style="color: gray">Free Pickup and Delivery Available</p>
  199.                         <div style="text-align: center; margin-top: 20px">
  200.                         <button class="btn btn-success">Shop Now</button>
  201.                         </div>
  202.                     </div>
  203.             </div>
  204.         </div>
  205.     </div>
  206. </div>
  207.  
  208. <div style="text-align: center;margin-top: 50px;">
  209.     <h1 class="display-4">From The Blog</h1>
  210.     <h3 style="color: green; font-weight: bolder">---------</h3>
  211. </div>
  212.  
  213.  
  214. <div class="container" style="padding-top: 10px; margin-top: 40px">
  215.     <div class="row" style="justify-content: center">
  216.          
  217.        
  218.         <div class="col-md-4 card mb-4" >
  219.             <div class="card"  >
  220.                 <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" >
  221.          
  222.                 </div>
  223.        
  224.                 <div class="card-body" style="text-align: left; background-color: white; color: black">
  225.                     <p style="margin-top: 20px; font-size: 25px;">May 16 2024</p>
  226.                     <h3
  227.                             style="margin-top: 20px">Vasina Cake</h3>
  228.                     <p style="margin-top: 20px; font-size: 25px;">Potrebni ni se 6 jajca i pritoa gi delime zolckite od belkite...</p>
  229.                 </div>
  230.             </div>
  231.         </div>
  232.        
  233.        
  234.                 <div class="col-md-4 card mb-4" >
  235.             <div class="card"  >
  236.                 <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" >
  237.          
  238.                 </div>
  239.        
  240.                 <div class="card-body" style="text-align: left; background-color: white; color: black">
  241.                     <p style="margin-top: 20px; font-size: 25px;">May 16 2024</p>
  242.                     <h3
  243.                             style="margin-top: 20px">Vasina Cake</h3>
  244.                     <p style="margin-top: 20px; font-size: 25px;">Potrebni ni se 6 jajca i pritoa gi delime zolckite od belkite...</p>
  245.                 </div>
  246.             </div>
  247.         </div>
  248.        
  249.        
  250.                 <div class="col-md-4 card mb-4" >
  251.             <div class="card"  >
  252.                 <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" >
  253.          
  254.                 </div>
  255.        
  256.                 <div class="card-body" style="text-align: left; background-color: white; color: black">
  257.                     <p style="margin-top: 20px; font-size: 25px;">May 16 2024</p>
  258.                     <h3
  259.                             style="margin-top: 20px">Vasina Cake</h3>
  260.                     <p style="margin-top: 20px; font-size: 25px;">Potrebni ni se 6 jajca i pritoa gi delime zolckite od belkite...</p>
  261.                 </div>
  262.             </div>
  263.         </div>
  264.        
  265.        
  266.     </div>
  267. </div>
  268.  
  269.  
  270. <footer class="bg-info" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
  271.  
  272.    
  273.    
  274.     <div class="container" style="margin-top: 30px; margin-bottom:30px">
  275.     <div class="row" style="justify-content: center">
  276.          
  277.        
  278.         <div class="col-md-4" >
  279.             <h5>FINKI EXAM</h5>
  280.             <p>Sveti Nikole</p>
  281.             <p>Sveti Nikole</p>
  282.             <p>Sveti Nikole</p>
  283.         </div>
  284.        
  285.                 <div class="col-md-4" >
  286.             <h5>FINKI EXAM</h5>
  287.             <p>Sveti Nikole</p>
  288.             <p>Sveti Nikole</p>
  289.             <p>Sveti Nikole</p>
  290.         </div>
  291.        
  292.                 <div class="col-md-4" >
  293.             <h5>FINKI EXAM</h5>
  294.             <p>Sveti Nikole</p>
  295.             <p>Sveti Nikole</p>
  296.             <p>Sveti Nikole</p>
  297.         </div>
  298.        
  299.        
  300.     </div>
  301.     </div>
  302. </footer>
  303.  
  304.  
  305. </body>
  306. ----------------------------outOfStock.html------------------------------------
  307.  
  308. <body>
  309.  
  310.  
  311.  
  312. <div style="text-align: center;margin-top: 50px;">
  313.     <h1 class="display-4">Out Of Stock</h1>
  314.     <h3 style="color: green; font-weight: bolder">---------</h3>
  315. </div>
  316.  
  317.  
  318.  
  319.  
  320. <div class="container" style="padding-top: 40px;">
  321.     <div class="row" style="justify-content: center">
  322.         {% for produkt in produkts %}
  323.          <div class="col-md-3 card mb-3" style="max-width: 18rem;">
  324.              <div class="card" style="width: 18rem;" >
  325.   <img src= "{{ MEDIA_URL }} {{ produkt.fotografija.url }}" alt="...">
  326.   <div class="card-body " style="text-align: center">
  327.       <h4 class="card-title"><b> {{produkt.ime}}</b></h4>
  328.     <h5 class="card-title">${{produkt.cena}}</h5>
  329.     <p>{{produkt.opis}}</p>
  330.   </div>
  331. </div>
  332.          </div>
  333.  
  334.         {% endfor %}
  335.     </div>
  336. </div>
  337.  
  338.  
  339. <div class="container" style="padding: 20px; background-color: whitesmoke; box-shadow: black; margin-top: 40px">
  340.     <form method="post" enctype="multipart/form-data">
  341.         {% csrf_token %}
  342.         {{ form.as_p }}
  343.         <button class="btn btn-primary" type="submit">Submit</button>
  344.     </form>
  345. </div>
  346.  
  347. <footer class="bg-info" style="padding-top: 20px; padding-bottom: 20px; margin-top: 40px">
  348.  
  349.    
  350.    
  351.     <div class="container" style="margin-top: 30px; margin-bottom:30px">
  352.     <div class="row" style="justify-content: center">
  353.          
  354.        
  355.         <div class="col-md-4" >
  356.             <h5>FINKI EXAM</h5>
  357.             <p>Organisation</p>
  358.             <p>Organisation</p>
  359.             <p>Organisation</p>
  360.         </div>
  361.        
  362.                 <div class="col-md-4" >
  363.             <h5>FINKI EXAM</h5>
  364.             <p>Organisation</p>
  365.             <p>Organisation</p>
  366.             <p>Organisation</p>
  367.         </div>
  368.        
  369.                 <div class="col-md-4" >
  370.             <h5>FINKI EXAM</h5>
  371.             <p>Organisation</p>
  372.             <p>Organisation</p>
  373.             <p>Organisation</p>
  374.         </div>
  375.        
  376.        
  377.     </div>
  378.     </div>
  379. </footer>
  380.  
  381.  
  382. </body>
  383.  
  384.  
  385.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement