This file contains hidden or 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
| import csv | |
| from django.http import HttpResponse | |
| from django.contrib.auth.models import User | |
| def user_csv(request): | |
| response = HttpResponse(content_type='text/csv') | |
| response['Content-Disposition'] = 'attachment; filename="users.csv"' | |
| csv_writer = csv.writer(response) |
This file contains hidden or 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
| from your_app import views | |
| from django.urls import path | |
| urlpatterns = [ | |
| ... | |
| path('csv/', views.user_csv, name='users_csv'), | |
| ] |
This file contains hidden or 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
| ............... | |
| <a href="{% url 'users_csv' %}">Export CSV</a> | |
| ............... |
This file contains hidden or 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
| Type 'manage.py help <subcommand>' for help on a specific subcommand. | |
| Available subcommands: | |
| [auth] | |
| changepassword | |
| createsuperuser | |
| [contenttypes] | |
| remove_stale_contenttypes |
This file contains hidden or 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
| from django.core.management.base import BaseCommand | |
| from django.utils import timezone | |
| class Mycommand(BaseCommand): | |
| help = 'Test if custom command is working or not' | |
| def handle(self, *args, **kwargs): | |
| self.stdout.write("Hi all set, it is working.") |
This file contains hidden or 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
| @receiver(m2m_changed, sender=Order.order_name.through) | |
| def checkquan(sender, instance, **kwargs): | |
| print("Working") | |
| prod = instance.order_name.all() | |
| for p in prod: | |
| p.quantity -= instance.order_quantity | |
| p.save() |
This file contains hidden or 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
| class Upload(models.Model): | |
| title = models.CharField(max_length=50) | |
| image = models.ImageField() | |
| def __str__(self): | |
| return self.title |
This file contains hidden or 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
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>Document</title> | |
| <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" | |
| integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous"> | |
| <!-- Latest compiled and minified JavaScript --> |
This file contains hidden or 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
| from django import forms | |
| from upload.models import Upload | |
| class UploadForm(forms.ModelForm): | |
| class Meta: | |
| model = Upload | |
| fields = ['title', 'image'] |
This file contains hidden or 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
| from django.shortcuts import render | |
| from django.views.generic import View | |
| from upload.forms import UploadForm | |
| from django.http import JsonResponse | |
| # Create your views here. | |
| class HomeView(View): | |
| def get(self, request): | |
| form = UploadForm() |
OlderNewer