Bok Nebojša,
mislim da je stvar u HTML možda prije, jer mi je ranije sve radilo..u
jednom trenu je puknula veza. Neznam točno kada.
Znači, da odem na url *productsgrouping *prikaze sve grupe, kad kliknem na
grupu (dodam joj a=href) no reverse mathc, ako maknem atribute u url
dobijem #, a ako ručno upišem productsgrouping/update/1 onda prikaze i
nastavi sve kako treba.
Znaci samo nemogu povezati ta dva linka....pogledaj htmlove u privitku
hvala ti za pomoć
uto, 29. sij 2019. u 11:35 Nebojsa Hajdukovic <[email protected]>
napisao je:
> A što ne uradiš update preko class based view daleko je lakše?
>
> https://docs.djangoproject.com/en/2.1/ref/class-based-views/generic-editing/
>
> Ako hoćeš preko funkcije ja radim sa get_object_or_404, ovako:
> def productsgrouping_update_view(request, url_id):
> product_lista = get_object_or_404(MaterialGroup, pk=url_id)
>
>
> уто, 29. јан 2019. у 10:20 Ivan Martić <[email protected]> је
> написао/ла:
>
>> not sure what to say
>>
>> čet, 24. sij 2019. u 13:53 Ivan Martić <[email protected]> napisao
>> je:
>>
>>> Hi Andréas,
>>> sorry for misspeling in codes. All is working ok except when i try to
>>> put url tag for 'update_productsgrouping'.
>>> I need to update group with new products but It does not argument for
>>> group id.
>>> What do you think i am doing wrong...?
>>>
>>> čet, 24. sij 2019. u 13:43 Andréas Kühne <[email protected]>
>>> napisao je:
>>>
>>>> Hi,
>>>>
>>>> The reason you are getting this is that you are adding an argument to
>>>> the productsgrouping url - which doesn't take any arguments.
>>>>
>>>> In your code you have:
>>>> <a href="{% url 'productsgrouping' item.id%}"></a>
>>>> (Which by the way isn't correct either, I think you mean: <a href="{%
>>>> url 'productsgrouping' item.id%}">{{ item }} - {{item.id}} </a>)
>>>>
>>>> If you look at the url for the producsgrouping view, you have:
>>>> path('', views.productsgrouping_view, name='productsgrouping'),
>>>>
>>>> Which doesn't take any arguments, when you then add an argument django
>>>> can't find the right URL.
>>>>
>>>> You may mean:
>>>> <a href="{% url 'update_productsgrouping' item.id%}">{{ item }} - {{
>>>> item.id}} </a>
>>>> ?
>>>>
>>>> Regards,
>>>>
>>>> Andréas
>>>>
>>>>
>>>> Den tors 24 jan. 2019 kl 13:28 skrev Ivan Martić <[email protected]
>>>> >:
>>>>
>>>>> Hi all,
>>>>>
>>>>> i am having issue with url tag, every time i put url tag like --{% url
>>>>> 'productsgrouping' item.id%}-- i get no reverse error.
>>>>> Can you help me figure it out on what am i doing wrong?
>>>>>
>>>>> view:
>>>>> def productsgrouping_view(request):
>>>>> queryset = MaterialGroup.objects.all()
>>>>> context = {"list" : queryset}
>>>>> return render(request, 'qif/productsgrouping/productsgroup.html',
>>>>> context)
>>>>>
>>>>> def productsgrouping_update_view(request, url_id):
>>>>> product_lista = MaterialGroup.objects.get(id=url_id)
>>>>> product_url_id = ProductgroupinputForm(request.POST or None,
>>>>> instance=product_lista)
>>>>> context1 = {'product_url_id': product_url_id, 'product_lista':
>>>>> product_lista}
>>>>>
>>>>> if product_url_id.is_valid():
>>>>> product_url_id.save()
>>>>>
>>>>> return render(request, 'productsgroup-update.html', context1)
>>>>>
>>>>> url:
>>>>> urlpatterns = [
>>>>> path('', views.productsgrouping_view, name='productsgrouping'),
>>>>> path('update/<int:url_id>/', views.productsgrouping_update_view,
>>>>> name='update_productsgrouping'),
>>>>> path('new/', views.creategroup_view, name='create_group'),
>>>>> ]
>>>>>
>>>>> html:
>>>>> {% extends 'base.html' %}
>>>>> {% block content %}
>>>>> <ul >
>>>>> {% for item in list %}
>>>>> <h1>
>>>>> <a href="{% url 'productsgrouping' item.id%}"></a>
>>>>> {{ item }} - {{item.id}}
>>>>> </h1>
>>>>> {% endfor %}
>>>>> {% endblock %}
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Django users" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to [email protected].
>>>>> To post to this group, send email to [email protected].
>>>>> Visit this group at https://groups.google.com/group/django-users.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/django-users/ca1ef95d-166a-40ef-91bc-16f2d704f2ee%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/django-users/ca1ef95d-166a-40ef-91bc-16f2d704f2ee%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Django users" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> To post to this group, send email to [email protected].
>>>> Visit this group at https://groups.google.com/group/django-users.
>>>> To view this discussion on the web visit
>>>> https://groups.google.com/d/msgid/django-users/CAK4qSCcnxCFkss1b8sOTDW3Kb6Vc1fFst4MO024%2BEq%3DwXLGjcg%40mail.gmail.com
>>>> <https://groups.google.com/d/msgid/django-users/CAK4qSCcnxCFkss1b8sOTDW3Kb6Vc1fFst4MO024%2BEq%3DwXLGjcg%40mail.gmail.com?utm_medium=email&utm_source=footer>
>>>> .
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>> To post to this group, send email to [email protected].
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CAFab_C8HUsxdpqz-MGqcpw0ZwgFOvrYZ-RJte6-H5x38b97ciQ%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CAFab_C8HUsxdpqz-MGqcpw0ZwgFOvrYZ-RJte6-H5x38b97ciQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAJ60hW3aGwHHutJiXASPkmgDKtn1g1QBgU4PpcuKa1zodypfRQ%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAJ60hW3aGwHHutJiXASPkmgDKtn1g1QBgU4PpcuKa1zodypfRQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAFab_C8ZxPMgVB6Z%3DXZ3OxNa8wQmvfmCtsvDKaxifmXHV1eZhA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
{% extends 'qif/base.html' %}
{% load crispy_forms_tags %}
{% block content %}
<br>
<div class="container">
<div class="row">
<h1 class="text-align-center">
<strong>{{ product_lista }} group</strong>
</h1>
</div>
<div>
<div class="col">
<p><h3>List of assigned products in group :</h3> </p>
</div>
</div>
</div>
{% for item in assigned %}
<div class="container">
<div class="row">
<div class="col-6">
<div class="funkyradio">
<div class="funkyradio-default">
<input type="checkbox" name="checkbox" id="checkbox1" />
<label for="checkbox1"><strong>{{ item.material_name
}}</strong> {{ item.materialid }}</label>
</div>
</div>
</div>
<br>
<div class="col-md-6">
<h4>Do you want to remove selected products from the <strong> {{
product_lista }}</strong> group</h4>
<button type="submit" name="delete" class="btn
btn-danger">Remove</button>
</div>
</div>
</div>
{% endfor %}
<br>
<hr>
<div class="container">
<div class="row">
<h3>
Search for non assigned products and assign them to this {{
product_lista }} group:
<br>
<form class="form-inline">
<input
class="form-control mr-sm-2"
type="search"
placeholder="Search"
aria-label="Search"
name="search"
value="{{ search_term }}">
<button class="btn btn-outline-success my-2 my-sm-0"
type="submit">Search</button>
</form>
</h3>
</div>
</div>
<div class="container">
<div class="row">
<div class="col">
{% if search%}
{% for item in not_assigned %}
<div class="funkyradio">
<div class="funkyradio-default">
<input type="checkbox" name="checkbox" id="checkbox1" />
<label for="checkbox1">
<strong>{{ item.material_name }}</strong>
{{ item.materialid }}
<em>bukrs {{item.bukrs}}</em>
</label>
</div>
</div>
{% endfor %}
{% endif %}
</div>
<div class="col-md-6">
<h4>Do you want to add selected products to the <strong> {{
product_lista }}</strong> group</h4>
<button type="submit" name="delete" class="btn
btn-success">Add</button>
</div>
</div>
</div>
<!-- <div>
<h3>
{{ products }}
</h3>
</div> -->
<!-- forma za search -->
<!-- <form method="GET" action="">
<input type="text" name="q" placeholder="Search the item" value="{{
request.GET.q }}"/>
<input type="submit" value="Search" />
</form> -->
<!-- ovo je test ispis liste -->
<!-- {% for item in not_assigned %}
{{ item.material_name }}
{% endfor %}
<hr> -->
<!-- ovo je forma sa checkboxovima -->
<!-- <form action="" method="post">
{% for proba in not_assigned %}
<input type="checkbox" value="{{proba.id}}" name="my_object">
{{ proba.material_name }}
<br>
{% endfor %}
<h4>Add selected products to the <strong> {{ product_lista }}</strong>
group</h4>
<button type="submit" name="delete">Add</button>
</form>
<br>
<form action="" method="post">
{% for proba in not_assigned %}
{{ proba.material_name }}
{% endfor %}
<h4>Add selected products to the <strong> {{ product_lista }}</strong>
group</h4>
<button type="submit" name="delete">Add</button>
</form> -->
<div class="float-right">
<p class="btn btn-info"><a href="{% url 'index' %}">Go back</a></p>
</div>
{% endblock %}from django.shortcuts import render, redirect
from django.http import HttpResponse
from .models import Material, MaterialGroup
from django.db import connection
from .forms import ProductgroupinputForm, MaterialGroupForm
from django.core.mail import send_mail
from django.conf import settings
from django.core.mail import send_mail
from django.contrib import messages
from django.db.models import Q
from django.contrib.auth import login, logout
from django.contrib.auth.decorators import user_passes_test, login_required
def check_user(user):
if user.groups.filter(name='productsgrouping_all').count() == 1:
return True
return False
#novi views
@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')
def productsgrouping_view(request):
queryset = MaterialGroup.objects.all()
not_assigned = Material.objects.filter(input_group__isnull=True).count()
context = {
"lista" : queryset,
"not_assigned":not_assigned
}
return render(request, 'qif/productsgrouping/productsgroup.html',
context)
@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')
def productsgrouping_update_view(request, url_id):
assigned = Material.objects.filter(id=url_id)
not_assigned = None
search = request.GET.get("search", None)
if search:
not_assigned = Material.objects.filter(Q(id__icontains=search)
| Q(maktx__icontains=search))
product_lista = MaterialGroup.objects.get(id=url_id)
product_url_id = ProductgroupinputForm(request.POST or None,
instance=product_lista)
context1 = {
'product_url_id': product_url_id,
'product_lista': product_lista,
'assigned':assigned,
'not_assigned':not_assigned,
'search': search,
}
if product_url_id.is_valid():
product_url_id.save()
messages.success(request, 'Your entry has been saved. Relevant
persons will be informed of this change.')
#time.sleep(5)
return render(request,
'qif/productsgrouping/productsgroup-update.html', context1)
@login_required(login_url='/accounts/login/')
@user_passes_test(check_user, login_url='/denied')
def creategroup_view(request):
forma = MaterialGroupForm(request.POST or None)
return render(request,
'qif/productsgrouping/productsgroup-create.html', {'forma':forma}){% extends 'qif/base.html' %}
{% block content %}
<br>
<div class="container">
<div class="panel panel-primary">
<div class="panel-heading">
{% for item in lista %}
<h2>
{{ item }}
</h2>
{% endfor %}
</div>
</div>
</div>
<div class="panel panel-default">
<div class="panel-heading">Panel Heading</div>
<div class="panel-body">Panel Content</div>
</div>
<ul >
{% for item in lista %}
<br>
<!-- ovdje ubacujem {% url 'update_productsgrouping' item.id%} i
nece raditi......hm-->
<a href="">
<h1>
{{ item }} - {{item.id}}
</a>
</h1>
{% endfor %}
<p>
<a href="{% url 'create_group' %}">nova grupa</a>
</p>
<div class="float-right">
<p class="btn btn-info"><a href="{% url 'index' %}">Go back</a></p>
</div>
{% endblock %}