-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5fd020
commit 8068e29
Showing
6 changed files
with
77 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. | ||
from .models import Item | ||
|
||
|
||
admin.site.register(Item) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from django import forms | ||
|
||
from .models import Item | ||
|
||
|
||
class ItemForm(forms.ModelForm): | ||
class Meta: | ||
model = Item | ||
fields = ['title', 'description'] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
URL configuration for cfehome project. | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/4.2/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
|
||
from django.urls import path | ||
|
||
from . import views | ||
|
||
app_name='items' | ||
urlpatterns = [ | ||
path("create/", views.item_create_view, name='create') | ||
] |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,22 @@ | ||
from django.contrib.auth.decorators import login_required | ||
from django.shortcuts import render | ||
|
||
# Create your views here. | ||
from .forms import ItemForm | ||
from .models import Item | ||
|
||
# @project_required | ||
@login_required | ||
def item_create_view(request): | ||
if not request.project.is_activated: | ||
return render(request, 'projects/activate.html', {}) | ||
form = ItemForm(request.POST or None) | ||
if form.is_valid(): | ||
item_obj = form.save(commit=False) | ||
item_obj.project = request.project | ||
item_obj.added_by = request.user | ||
item_obj.save() | ||
form = ItemForm() | ||
context = { | ||
"form": form | ||
} | ||
return render(request, 'items/create.html', context) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{% extends 'base.html' %} | ||
|
||
|
||
{% block content %} | ||
|
||
<h1>Create new item for {{ request.project.title }}</h1> | ||
<form method="post" action="">{% csrf_token %} | ||
|
||
{{ form.as_p }} | ||
|
||
<button type="submit">Create</button> | ||
|
||
</form> | ||
|
||
|
||
{% endblock content %} |