mayankvalechha / django-invoice Goto Github PK
View Code? Open in Web Editor NEWAn Invoice web app developed in Django
An Invoice web app developed in Django
Here is the code.
<div class="form-group mb-2">
<form method="POST" action="/search/">
{% csrf_token %}
<input type="date" name="search_by_date" required class="form-control mb-1">
<button type="submit" class="btn btn-primary btn-sm">Search</button>
</form>
</div>
This is my form, in which the there's a date input which lets you choose the date, and the form is submitted to search/ URL. But the generated URL is localhost.com/search/
What I want to do is, I want to generate a dynamic URL based on the date itself.
Example, If the user chooses the 10-08-2020 date, the URL should be localhost.com/search/10-08-2020
urlpatterns = [
...
path('search/', get_by_date, name='search'),
]
# Function used to get the data based on the entered date
def get_by_date(request):
if request.method == 'POST':
# query contains the date entered by the user
query = request.POST['search_by_date']
if query:
invoice_by_date = Invoice.objects.filter(purchase_date__icontains=query)
expense_by_date = Expense.objects.filter(expense_date__icontains=query)
# Summing the selling price by the date
amount = Invoice.objects.filter(purchase_date__icontains=query).aggregate(amount = Sum('selling_price'))['amount']
if invoice_by_date:
# Changing Format of Input Date to Display in Template
query = datetime.datetime.strptime(query, '%Y-%m-%d').strftime('%d-%B-%Y')
return render(request, 'invoice/get_by_date.html',
{ 'query_result':invoice_by_date,
'query_date':query,
'amount': amount,
'query_result2': expense_by_date,
})
else:
return render(request, 'invoice/get_by_date.html')
else:
return HttpResponse('No Data Found!')
else:
return HttpResponse('No Data Found!')
Screenshots:
User Selects the date in the date field and press submit button.
The URL that comes in the URL bar is this.
Any help would be appreciated.
Thank you!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.