Skip to content

Commit

Permalink
feat: add page to create listing
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasFASouza committed Jan 31, 2023
1 parent ed4aa72 commit dc10c88
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions auctions/forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django import forms


class NewListing(forms.Form):
title = forms.CharField(label="Listing Title", max_length=64)
description = forms.CharField(
label="Listing Description",
widget=forms.Textarea(attrs={'rows': 1, 'cols': 1})
)
initial_bid = forms.DecimalField(label="Initial Bid", max_digits=6, decimal_places=2)
photo_url = forms.URLField(label="Photo URL")

CATEGORIES_CHOICES = (
('Fashion', 'Fashion'),
('Home', 'Home'),
('Electronics', 'Electronics'),
('Toys', 'Toys'),
('Other', 'Other')
)

category = forms.ChoiceField(label="Category", choices=CATEGORIES_CHOICES)
13 changes: 13 additions & 0 deletions auctions/templates/auctions/add.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "auctions/layout.html" %}

{% block body %}
<h2>New Listing</h2>

<form action="{% url 'add' %}" method="post">
{% csrf_token %}
{{ form }}
<input type="submit">
</form>

<a href="{% url 'index' %}">All Listings</a>
{% endblock %}
3 changes: 3 additions & 0 deletions auctions/templates/auctions/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ <h1>Auctions</h1>
<li class="nav-item">
<a class="nav-link" href="{% url 'logout' %}">Log Out</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'add' %}">Add new listing</a>
</li>
{% else %}
<li class="nav-item">
<a class="nav-link" href="{% url 'login' %}">Log In</a>
Expand Down
1 change: 1 addition & 0 deletions auctions/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path("logout", views.logout_view, name="logout"),
path("register", views.register, name="register"),
path("<int:listing_id>", views.listing, name="listing"),
path("add", views.add_listing, name="add")
]
7 changes: 7 additions & 0 deletions auctions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from django.urls import reverse

from .models import User, Listing
from . import forms


def index(request):
Expand Down Expand Up @@ -72,3 +73,9 @@ def listing(request, listing_id):
"listing": auction,
"bidings": bidings
})


def add_listing(request):
return render(request, "auctions/add.html", {
"form": forms.NewListing()
})

0 comments on commit dc10c88

Please sign in to comment.