Giter Site home page Giter Site logo

django-invoice's People

Contributors

mayankvalechha avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

django-invoice's Issues

I want to generate a Dynamic URL based on date, such as localhost.com/search/dd-mm-yyyy.

Here is the code.

index.html

<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

urls.py

urlpatterns = [
    ...
    path('search/', get_by_date, name='search'),
]

view.py

# 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.
search

The URL that comes in the URL bar is this.
url

Any help would be appreciated.
Thank you!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.