mirror of
https://github.com/inventree/InvenTree.git
synced 2025-04-29 12:06:44 +00:00
Added "new part" feature
- Create a new part - Button provided on the "category" list page
This commit is contained in:
parent
ff2082b156
commit
2c2db4fffb
18
InvenTree/part/templates/part/create.html
Normal file
18
InvenTree/part/templates/part/create.html
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% load static %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
|
||||||
|
{% include "part/cat_link.html" with category=category %}
|
||||||
|
|
||||||
|
<div class='panel panel-primary'>
|
||||||
|
<div class='panel-heading'>Create a new part{% if category %} in category '{{ category.name }}'{% endif %}</div>
|
||||||
|
<div class='panel-body'>
|
||||||
|
|
||||||
|
{% load crispy_forms_tags %}
|
||||||
|
{% crispy form %}
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{% endblock %}
|
@ -28,5 +28,8 @@ Parts:
|
|||||||
</ul>
|
</ul>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
<a href="/part/create/{% if category %}?category={{ category.id }}{% endif %}">
|
||||||
|
<button class="btn btn-default">New Part</button>
|
||||||
|
</a>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
|
@ -54,6 +54,9 @@ part_detail_urls = [
|
|||||||
|
|
||||||
# URL list for part web interface
|
# URL list for part web interface
|
||||||
part_urls = [
|
part_urls = [
|
||||||
|
# Create a new part
|
||||||
|
url(r'^create/?', views.PartCreate.as_view(), name='part-create'),
|
||||||
|
|
||||||
# Individual
|
# Individual
|
||||||
url(r'^(?P<pk>\d+)/', include(part_detail_urls)),
|
url(r'^(?P<pk>\d+)/', include(part_detail_urls)),
|
||||||
|
|
||||||
|
@ -34,6 +34,40 @@ class PartIndex(ListView):
|
|||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
class PartCreate(CreateView):
|
||||||
|
""" Create a new part
|
||||||
|
- Optionally provide a category object as initial data
|
||||||
|
"""
|
||||||
|
model = Part
|
||||||
|
form_class = EditPartForm
|
||||||
|
template_name = 'part/create.html'
|
||||||
|
|
||||||
|
def get_category_id(self):
|
||||||
|
return self.request.GET.get('category', None)
|
||||||
|
|
||||||
|
# If a category is provided in the URL, pass that to the page context
|
||||||
|
def get_context_data(self, **kwargs):
|
||||||
|
context = super(PartCreate, self).get_context_data(**kwargs)
|
||||||
|
|
||||||
|
# Add category information to the page
|
||||||
|
cat_id = self.get_category_id()
|
||||||
|
|
||||||
|
if cat_id:
|
||||||
|
context['category'] = get_object_or_404(PartCategory, pk=cat_id)
|
||||||
|
|
||||||
|
return context
|
||||||
|
|
||||||
|
# Pre-fill the category field if a valid category is provided
|
||||||
|
def get_initial(self):
|
||||||
|
|
||||||
|
initials = super(PartCreate, self).get_initial().copy()
|
||||||
|
|
||||||
|
if self.get_category_id():
|
||||||
|
initials['category'] = get_object_or_404(PartCategory, pk=self.get_category_id())
|
||||||
|
|
||||||
|
return initials
|
||||||
|
|
||||||
|
|
||||||
class PartDetail(DetailView):
|
class PartDetail(DetailView):
|
||||||
context_object_name = 'part'
|
context_object_name = 'part'
|
||||||
queryset = Part.objects.all()
|
queryset = Part.objects.all()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user